Reputation: 11
I am trying to make a multiple upload system for images. I am using input type of file with multiple files upload. I want to have checks for each and every file and upload only if they pass all the checks, otherwise stop uploading the current (failing) file but continue for remaining files. I want to do it with Javascript and PHP. Can anyone suggest what steps to follow? No JQuery, please.
<input id="uploadfiles" style="overflow:hidden" type="file" name="files[]" value="upload" multiple />
Upvotes: 0
Views: 82
Reputation: 1511
Let me summarize generic upload process:
This clearly shows one thing: If you want to validate files by PHP script, all of the files must have been fully uploaded already, this means you can not call the script for each file separately while others are uploading (not with html and regular forms).
Also (depending on requirements you need to check on files) you may not be able to validate files with javascript for some security reasons.
So there is simple (but not much satisfying) solution. Let the user upload all files, then validate them one by one with your javascript. If they pass your requirements, copy them to intended folder, if not you can just leave them intact and they will be erased from the tmp folder. It has only one downside, the user will need to wait long time when uploading large file before they know it did not pass requirements.
Upvotes: 1