How should I go about handling http uploads that exceeds the post_max_size in a sane manner?
In my configuration post_max_size is a few MB
I liked @Matthew answer, but needed a version that checked for multiple upload files.
This was my solution:
function checkAttachmentsSize() {
var total = 0;
var count = 0;
jQuery('input[type="file"]').each(
function() {
if (typeof this.files[0] != 'undefined') {
total+= this.files[0].size;
count++;
}
}
);
var word = (count > 1) ? 's are' : ' is';
if (total > (uploadMax * 1000 * 1000)) {
alert("The attachment file" + word + " too large to upload.");
return false;
}
return true;
}
And, for completeness, here's the binding of the function to the form being submitted:
jQuery(function($) {
$("form").submit(
function() {
return checkAttachmentsSize();
}
});
);
NOTE:
uploadMax is a variable that I set via php after calculating the maximum size of the allowable upload.