My site uploads multiple images all at once, which leads to eternal loading duration for my php files. Now I want to try to split the files from and upload all images seperate, so I can show a process bar and not a loading php for 10 minutes.
First I tried to get the files using FileList. But I am not able to add the seperated files onto the input tag inner the iframe, because of security reasons.
My next attempt would be FormData objects, but I dissuade from using these, because of bad browser support.
Do you have any suggestions for a more pleasent way to upload files?
<input type="file" id="gallery" multiple="true" />
<script defer="true">
var pullfiles=function(){
// love the query selector
var fileInput = document.getElementById("gallery");
var files = fileInput.files;
// cache files.length
var fl = files.length;
var i = 0;
while ( i < fl) {
// localize file var in the loop
var file = files[i];
var ip = document.createElement("input");
ip.setAttribute("type", "file");
ip.value = file; //generates security error
document.body.appendChild(ip);
i++;
}
}
// set the input element onchange to call pullfiles
document.getElementById("gallery").onchange=pullfiles;
//made by Mozilla as an example for FileList Objects -> https://developer.mozilla.org/en-US/docs/Web/API/FileList#Example
</script>
Aucun commentaire:
Enregistrer un commentaire