I'm having an issue with implementing the jQuery file upload plugin (https://github.com/blueimp/jQuery-File-Upload/wiki/Options).
My form has a file field set to multiple and a number of regular input fields. I'm using PHP to handle the form on the server side.
The problem seems to occur when I select several large files to upload and submit the form, in which case the $_POST and $_FILES arrays are empty.
I haven't to been able to figure out exactly when this happens - at first I though it occurred when selecting large files so that the total size of the files exceeded my max file size upload limit, but this doesn't seem to be the case.
It seems the problem lies on the client side, since it appears that no form data is sent to the server at all in these cases.
Has anyone had this problem and is there a solution?
UPDATE
The problem seems to be that PHP removes all data in $_POST and $_FILES if the submit size is larger than the max allowed upload size. It was my understanding that this plugin could make several requests to upload multiple files to avoid this problem, but no matter what settings I use I can't get this to work.
So, let me try to explain a bit better what I'm trying to achieve. The user can enter info in the form and can also choose to attach any number of files. The file size for each file must not be larger than the max allowed upload limit, but it's possible that the user selects several files whose total file size will be larger than the maximum. In this case I would like the plugin to make several requests to the server, making sure that each request stays below the size limit. But I can't get this to work. Only one request is ever made.
Here's the current version of my code
$('#applicationform').fileupload({
autoUpload: false,
singleFileUploads: false,
//limitMultiFileUploads: 3,
//sequentialUploads: true,
//limitMultiFileUploads: 3,
//limitMultiFileUploadSize: 1000000,
dataType: 'json',
progress: function(e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
},
add: function (e, data) {
$("#applicationform-submit").off('click').on('click', function (e) {
e.preventDefault();
data.formData = $("#applicationform").serializeArray();
data.submit();
console.log("submit", data.files);
});
});
The server uses the php code provided by the plugin to save the files to the server and each request returns a JSON array with the files the user uploaded. For example:
{"files":[{"name":"Screen Shot 2017-07-24 at 20.28.48 (3).png","size":1289712,"type":"image\/png","url":"[snip]","thumbnailUrl":"[snip]","deleteUrl":"[snip]","deleteType":"DELETE"}]}