For a simple fix that does not require changes on the server side, I would use the HTML5 file API to check the file size before downloading. If it exceeds a known limit, cancel the download. I believe something like this will work:
function on_submit() { if (document.getElementById("upload").files[0].size > 666) { alert("File is too big."); return false; } return true; } <form onsubmit="return on_submit()"> <input id="upload" type="file" /> </form>
Obviously, this is just an example skeleton, and not every browser supports this. But this does not hurt to use it, because it can be implemented in such a way that it does not elegantly turn into nothing for older browsers.
Of course, this does not solve the problem, but at least it will support a number of your users with minimal effort. (And they donβt even have to wait until the download is complete.)
-
Aside, checking $_SERVER['CONTENT_LENGTH'] and the size of the message and file data may help to find that something failed. I think that when there is an error, it will not be zero, and the tags $_POST and $_FILES will be empty.
Matthew
source share