Download multiple files using PHP / Javascript and without flash

I am trying to create a web page that allows you to upload multiple files at once. I will limit file extensions to the most common images such as jpg, jpeg, png and gif.

I have done some research on this, and everywhere I watch it flare up and flare up.

I do not want to use flash. Especially with Flash 10, which disables the most common used method for multipoint downloads.

What I'm looking for is a way to save more and more input fields, each with a browse button, and then with one last download button at the bottom of the form. Creating new input fields using Javascript is really a big problem.

So I wonder how it works. Do I have to give all the input fields the same name, so I can use 1 part of the PHP code to solve this problem? Or is there some way for PHP to detect how many files have been disabled and just put the code to parse the file inside the for loop?

+4
source share
4 answers

Here is the algorithm:

You add new file input fields to your form. Each of these fields MUST have a unique name. Then, on the server side, you look at the $ _FILES array, looking at how many files have been downloaded and processed.

+2
source

You can add file attachments, but use a name something like "upload []"

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

Then in $ _FILES ['upload'] you will have an array of files that you can iterate over, for example

 foreach ($_FILES['upload'] as $file) { echo $file['size']; } 
+12
source

When using JavaScript to add new fields for loading, you can also update JavaScript in some "hidden" input field with the number of fields to load in the form. Thus, as soon as you click Submit, this hidden value should be presented, and it will be trivial to parse the $ _FILES array for all uploaded files.

0
source

If you have a reasonable maximum limit on the number of files, it is probably better to include this many fields for uploading files in a static form, and then use JavaScript to hide the redundant ones than creating them all dynamically. Then the form can work when JavaScript is not available.

Side note: technically separate forms for uploading HTML files are already several forms for uploading files. According to the HTML form encoding standard, you need to be able to select multiple files in the Browse dialog box, and they will be presented as a multi-component / mixed MIME structure.

However, it practically does not support anything. Older versions of Opera work on the client side (and, I think, an ancient test browser of some kind, possibly Viola) and several components for parsing text on the server side, but not built-in PHP. In any case, the user interface is not very convenient, so you are missing a lot.

0
source

All Articles