I have a problem with a large file transfer using jquery ajax function and php by post method:
I have the javascript function:
function multimedia_update(){
if( contador_peticiones > 0 ){return;}
contador_peticiones++;
var formData = new FormData($('#sky-form')[0]);
$.ajax({
xhr: function()
{
var xhr = new window.XMLHttpRequest();
//Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = ((evt.loaded / evt.total)*100)-2;
//Do something with upload progress
$("#progreso").css('width', percentComplete+'%');
$("#progreso").html(percentComplete+'%');
}
}, false);
xhr.addEventListener("error", onError, false);
//Download progress
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = ((evt.loaded / evt.total)*100)-2;
//Do something with download progress
$("#progreso").css('width', percentComplete+'%');
$("#progreso").html(percentComplete+'%');
}
}, false);
return xhr;
},
type:"POST",
dataType:"JSONP",
url:"drivers/multimedia-update.php",
data:formData,
//necesario para subir archivos via ajax
cache: false,
contentType: false,
processData: false,
timeout: 3600000,
beforeSend: function(){
$('.alert-info').fadeIn();
},
success: function(datos){
var obj = jQuery.parseJSON( datos );
switch( parseInt(datos[0].respuesta_final) ){
case -1:
alert('Error al guardar');
break;
case 0:
alert('Hubo un problema al guardar alguna información, por favor notificar.');
break;
case 1:
alert('Éxito al guardar.');
break;
}
contador_peticiones = 0;
multimedia_grid();
},
error: function(jqXHR, status, error) {
mi_respuesta = jqXHR;
console.log(jqXHR);
console.log("espacio");
console.log(status);
console.log("espacio");
//console.log(error);
//alert("error en la petición 124");
}
})
.done(function(){
contador_peticiones = 0;
});
return false;
}
In PHP the code to upload file by a ftp client (SubirArchivo function):
if(isset ($_FILES['file2']['name']) ){
if( $_FILES['file2']['name'] != '' ){
$nombre_archivo_video = clean($_FILES["file2"]["name"]);
$nombre_archivo_video = substr(md5(uniqid(rand())),0,4).'_'.$nombre_archivo_video;
$directorio = '/video/repository/';
$respuesta2 = SubirArchivo($nombre_archivo_video, $_FILES["file2"]["tmp_name"], $directorio);
}
}
The form:
<form action="" id="sky-form" class="sky-form" enctype="multipart/form-data">
<fieldset>
<div class="row">
<section>
<p>Video</p>
<p>Archivo en formato mp4</p>
<label for="file" class="input input-file">
<div class="button">
<input id="file-4" type="file" class="file" name="file2" accept="video/mp4" onchange="this.parentNode.nextSibling.nextSibling.value = this.value" />Browse
</div>
<input type="text" placeholder="Video" readonly="" />
</label>
</section>
</div>
</fieldset>
</form>
My php.ini config:
max_execution_time = 0
max_input_time = -1
memory_limit = 512M
post_max_size = 368M
upload_max_filesize = 368M
The problem is that it not works with files larger to 80M, smaller it works fine, so I don't know exactly what is the bug.
I would like it to work with at least the limit of 300M.
I have been serach about my problem. I now add more information. When the error occurs, in console I print the XHR response that throws me: readystate 0, status 0 and statusText error. And I have tried to implement the following answers: link1, link2 But I still have the same problem. I'm still looking for...
Update:
Well then following the topic, I keep doing tests and now it turns out that it is not a problem of the file size. Apparently the file has a problem or error, however I still do not know exactly why. I was reading this problem when trying to load a docx file or an image with extension not supported by the GD.