Search code examples
phpjqueryajaxfile-uploadxmlhttprequest

Ajax not posting big files


I am uploading files with jQuery's ajax

$("#transfer").live("click", function()
{
    var data = new FormData();

    data.append("your_email", $("#your_email").val());
    data.append("your_message", $("#your_message").val());

    $.each($(".friends_email_item"), function(a,b)
    {
        var email = $(b).text();

        data.append("emails[]", email);
    });

    for(i = 0; i < files.length; i++)
        data.append("files[]", files[i]);

    $.ajax({
        url: "upload.php", 
        type: "POST",

        success: function(a)
        {
            console.log(a);
        },

        data: data,

        contentType: false,
        processData: false
    });
});

When I select a small file such as a text file or a screenshot. I get get a dump of the data posted and the files posted.

array
  'your_email' => string 'Hello@test.com' (length=14)
  'your_message' => string 'test' (length=7)

array
  'files' => 
    array
      'name' => 
        array
          0 => string '1.png' (length=5)
      'type' => 
        array
          0 => string 'image/png' (length=9)
      'tmp_name' => 
        array
          0 => string 'C:\wamp\tmp\phpBD32.tmp' (length=23)
      'error' => 
        array
          0 => int 0
      'size' => 
        array
          0 => int 117994

When I upload a 50mb zip or a 500mb video, I get an empty array back

array
  empty

array
  empty

Why is it failing to post any data when it is a big file?


Solution

  • check server configuration settings which will affect upload size restrictions: use phpinfo() to see the values

    • upload_max_filesize, which sets an upper limit on the size of uploaded files
    • post_max_size, which limits the total size of posted data, including file data
    • max_input_time, which restricts the length of time the script is allowed to process input data, including posted values

    upload_max_filesize is a limit on each individual file; however, post_max_size is an upper limit on the entire request, which includes all the uploaded files.