I'm trying to write service, what will upload files through XMLHttpRequest Level 2, but I have problems with big files (more than 60Mb). I receive this message (for 65 Mb)
Fatal error</b>: Allowed memory size of 209715200 bytes exhausted (tried to allocate 71899100 bytes)
Size of memory is 200 Mb and I can't guarantee that value on hosting will greater or the same at least. I don't understand, what to do to solve this problem. My code is here:
<form id="myform" name="myform">
<input type="file" name="failik" id="failik" onchange="sendFile(this.form);">
</form>
<div id="uploadProgress"></div>
<script type="text/javascript">
<!--
function sendFile(form) {
var files = document.getElementById("failik").files;
for (var i = 0; i < files.length; i ++) {
file = files[i];
var name = file.fileName != null ? file.fileName : file.name;
var size = file.fileSize != null ? file.fileSize : file.size;
var xhr = new XMLHttpRequest();
xhr.upload.onprogress = function(e){
if (e.lengthComputable){
var value = Math.round(e.loaded / e.total * 100);
var text = value + '% from ' + e.total;
document.getElementById("uploadProgress").innerHTML = text;
}
};
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
alert(xhr.responseText);
}
};
xhr.open("POST", "/do-nothing.php?file=" + name, true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
xhr.setRequestHeader("Content-Type", "application/octet-stream");
//I've tried to do this
var formData = new FormData();
formData.append(name, file);
xhr.send(formData);
//And this
var formData = new FormData(form);
xhr.send(formData);
//And this
xhr.send(file);
//But without result
}
}
//-->
</script>


Sign In
Create Account

Back to top










