Reputation: 33
I'm making a custom website for someone and the site requires that new users be able to upload multiple photos. I'm been looking at image uploading scripts, image host APIs, and making something from scratch. I know how to upload a single image using forms and PHP, but I don't know the best way to do it for multiple images.
What do you recommend?
Also, if I made something from scratch or used a script, and the image was stored in a folder on my server, is that safe? (Can people upload malicious files and run them)
Upvotes: 0
Views: 358
Reputation: 2119
For a simple multi-uploading method you can use a multiple attribute on the input tag:
<input type="file" multiple="multiple" />
However, the user can only select files visible in the current folder view; usually just one folder.
If you wanted to be able to add more files, perhaps dynamically apply display:none;
to the file input tag and add a new one in its place. To show which files have already been selected, list out the current files to be uploaded using javascript, as is seen here, multiple-file-upload.
Or skip the hiding step above so you have all the file upload forms visible at any given time, while dynamically keeping one blank one, so more files can be uploaded.
Be careful if you want valid XHTML/HTML as the multiple
attribute is still part of the HTML5 speculation (SPEC).
Another alternative would be to use iframes and reload the iframe when a file is uploaded, so the user can instantly choose another file.
I personally never use Frames, so I have no idea how this might work.
The so called "AJAX file uploader" methods are also just a clever iframe trick from what I have seen.
The only other option I can think is to statically have a lot of <input type="file"/>
s and hope your user needs no more than were provided.
I would personally just use the plain <input type="file" multiple="multiple"/>
as I would assume that most user's groups of pictures they are trying to upload simultaneously would be in the same folder.
Upvotes: 1