0

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.

Alejandro Díaz
  • 430
  • 4
  • 10
  • if your `var_dump ($_FILES) `you should see the error message –  Dec 16 '16 at 01:43
  • Thaks for your help. I tried your suggestion: when the escript finish (<80M) returns $_FILES array info .... But in large files it executes the javascript error block, in safari for example shows a "lost connection" message. – Alejandro Díaz Dec 17 '16 at 00:11

1 Answers1

0

Well I do not know if this is really an answer. But after a while I could corroborate that the error could be presented in shared servers, which supposedly give you the freedom to configure the file transfer parameters but they do not work. Specifically, the problem happened to me in the godaddy service and one that is called dissenynet. The problem was finally solved when the company hired a dedicated server (in my case, IBM cloud), I had to mount my own LAMP server and be able to configure the necessary variables. I can currently upload files up to 500 MB without problems. As an additional note, this type of conflicts can cause errors such as "HTTP error" in wordpress since the transfer is not handled correctly. Apparently the "special" services for wordpress have already solved this part since it is common that thanks to the freedoms that wordpress gives you, this type of error has been presented for a long time. I hope this will help.

Alejandro Díaz
  • 430
  • 4
  • 10