ajax - use html5 multiple attribute to trigger multiple single uploads -
sorry confusing title.
i have form-- form1 has 1 file input ( multiple attribute set user can select mutiple files). form doesn't submitted.
i have form -- form2 has single file input . no mutiple attribute.
now via javascript fetch each files fileinput previous form , assign file form2's input field , ajax submit. once ajax submit complete same 2nd file , 3rd file , on.
i don't want use flash or java applet. aware ie doesn't support multiple attribute opera can use invalid min max attribute same.
my basic question how fetch files form1 input field , assisgn form2's field ..
is there solution ? or approach incorrect ?
what want achieve on ui side ? file gets uploaded , server processing , returns data. want user can select 10 files 1st file uploaded output received.
first : idea wrong. cannot assign value via javascript input type = file .
i thought of idea using xmlhttprequest. here code :
<form id="new_picture_form" method="post" enctype="multipart/form-data" action="some url" accept-charset="utf-8"> <input id="original_input" class="file_hidden" type="file" onchange="handlefiles(this.files);" name="picture[image][]" multiple="multiple"> </form> <form id="fileinfo" method="post" enctype="multipart/form-data" action="some url"> </form> <script type="text/javascript"> function handlefiles(files) { (var = 0; < files.length; i++) { fileupload(files[i]) } } function fileupload(file) { var data = new formdata(document.getelementbyid("fileinfo")); var xhr = new xmlhttprequest(); this.xhr = xhr; data.append('some field',"that want pass param ") data.append('type',"picture") data.append("picture[image]", file); xhr.open("post", "url",true); xhr.send(data); xhr.onreadystatechange = function() { if (xhr.readystate == 4) { eval(xhr.responsetext) // result server contains script } } } </script>
Comments
Post a Comment