开发者

How can I get the html form name from php with multiple file uploads?

开发者 https://www.devze.com 2023-03-22 15:22 出处:网络
If I do something like this to get handle file uploads: if ($_FILES) { foreach ($_FILES as $file) { //...Handle the upload process

If I do something like this to get handle file uploads:

if ($_FILES) {
    foreach ($_FILES as $file) {
        //...Handle the upload process
    }
}

Is there any way that I can get the key of the file? As in:

<input type="file" name="myfile" />

I want to know that the file is coming from "myfile".

E开发者_JS百科dit: The obvious solution to this turns out to be:

foreach($_FILES as $key => $file) {

    $input_name = $key;
    // Handle upload.

}


If the input name in your form is myfile, then it will be in the $_FILES array as:

$_FILES['myfile']

So you can do:

foreach ($_FILES as $inputName => $fileInfo) {

}

Check out Handling file uploads for more info.

0

精彩评论

暂无评论...
验证码 换一张
取 消