html5 - Split multi-file post with Javascript before upload -
i understand html/php side of multi-file upload, suppose i'm after javascript solution separates files array pre-post , individually sends files separate php programme receive upload , success/fail feedback before continuing. (ie: files[0] -> post -> success -> files[1] -> post -> success ->etc...)
here utilize single file -
function upload(file){ var info = new formdata(); data.append("file", document.getelementbyid(file).files[0]); var xmlhttp = new xmlhttprequest(); xmlhttp.open("post", "uploader.php"); xmlhttp.send(data); } i realize easy way out create multiple file fields, i'm trying utilize <input type="file" multiple> html5 mass-select list of files @ time. if separate files javascript, simple matter of looping through above script onreadystatechange reporting success/fail each time.
any ideas?
edit: forgive tunnel vision, extremely simple! here's total code in case helps else out.
<html> <head> <script language="javascript"> function multiupload(file){ count = 0; maxcount = document.getelementbyid(file).files.length; alert(maxcount); upload(file,count); } function upload(file,count){ var info = new formdata(); data.append("file", document.getelementbyid(file).files[count]); var xmlhttp = new xmlhttprequest(); xmlhttp.open("post", "uploader.php"); xmlhttp.onreadystatechange=function(){ if (xmlhttp.readystate == 4 && xmlhttp.status == 200){ count = count+1; if(count<maxcount){ upload(file,count); } } } xmlhttp.send(data); } </script> </head> <body> <div id="result"></div> <form method="post" action=""> <input type="file" name="file" id="file" multiple> <input type="button" name="submit" value="upload" onclick="multiupload('file');void(0);"> </form> </body> </html>
try this. can start uploading next file in success handler. way can files[0] -> post -> success -> files1 -> post -> success
javascript html5 upload
No comments:
Post a Comment