1

I am currently working on a PHP website that has a file size upload limit of 32 MB (set in a php.ini file that I am not permitted to change), so my current plan is to parse the file in 32 MB chunks on the client side in Javascript and upload these chunks to our PHP server, where it reassembles them. I used the FileReader API to do so, as described in this post.

However, the files I receive on the PHP server (in $_FILES) have error 0 and size 0, even if I submit a small file well below 32 MB in size.

My callback function (used as callback() in the code from alediafaria's answer) is as follows:

var chunkDoneCallback = function(res, filename, count, total_count, filetype) { 
    var renamedFile = new File([res], count + "_" + total_count + "_" + filename, {type: filetype});
    console.log('Filename ' + renamedFile.name + ' (' + renamedFile.size + ' bytes)');
    console.log(renamedFile);
    var form_data = new FormData();                  
    form_data.append('testfile_chunk', renamedFile);
    var req = new XMLHttpRequest();
    req.onreadystatechange = function() {//Call a function when the state changes.
        if(req.readyState == XMLHttpRequest.DONE && req.status == 200) {
            // Request finished. Do processing here.
            console.log(req.response);
        }
     }
     req.open("POST", <?php  echo "\"".$_SERVER['PHP_SELF']."\"";?>);
     req.send(form_data);
}

This shows the renamedFile object has the correct name and size, but the file on the PHP side has the correct name and 0 size. If I use the exact same XMLHttpRequest code here to upload the original full-size file (assuming it's under 32 MB, of course), it uploads with the correct size. Same errors occur if I use AJAX in place of XMLHttpRequest.

Just about every answer I've seen online regarding error 0 and size 0 seems to indicate an issue with the php.ini max file size limitations, but I'm seeing this even with very small files. I've tried making the chunk size smaller, changing the MIME type in the requests, etc. to no success.

It feels like it's an issue with how FileReader is being used, but I don't see anything in its documentation that seems to be related to this. Any ideas? Thank you!

atitus
  • 11
  • 1

0 Answers0