graemeboy
graemeboy

Reputation: 610

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

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".

Edit: The obvious solution to this turns out to be:

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

    $input_name = $key;
    // Handle upload.

}

Upvotes: 0

Views: 75

Answers (1)

webbiedave
webbiedave

Reputation: 48897

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.

Upvotes: 1

Related Questions