Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi file upload with PHP/Javascript and no flash

I'm trying to make a webpage that allows the uploading of multiple files at the same times. I will limit the file extensions to the most common images like JPG, JPEG, PNG and GIF.

I've done some research on this and everywhere I look it's flash this and flash that.

I don't want to use flash really. Especially with Flash 10, which disables the most common used method to enable multifile upload.

What I'm looking for is a way to keep creating more and more input fields, each with a browse button and then with one final upload button at the bottom of the form. Creating the new input fields with a Javascript is nog big deal really.

So I'm wondering how this works. Do I need to give all file-input fields the same name atribute so I can use 1 piece of PHP code to solve this? Or Is there some way for PHP to detect howmany files have been sumbitted and simply put the code for parsing a file inside a for-loop?

like image 765
Vordreller Avatar asked Dec 10 '22 22:12

Vordreller


1 Answers

You can keep adding 'file' inputs but use a name of something like 'upload[]'

<input type="file" name="upload[]">

Then in $_FILES['upload'] you will have an array of files you can loop over like

foreach ($_FILES['upload'] as $file) {
    echo $file['size'];
}
like image 133
Tom Haigh Avatar answered Dec 13 '22 14:12

Tom Haigh