It is not possible to stop this from the server side - the file will still be loaded before PHP decides whether to reject it. You will need to add this discovery on the client side. Although you cannot do this with the usual HTML form, Flash downloaders can find out the file size before starting the download.
On the server side, you cannot use anything with PHP - the files were always fully loaded before PHP could say no. To block the download (i.e. disconnect part of the client part via POST), you will need the magic of the web server below the stack. Perlbal is capable of doing this. Writing your own Apache module is a solution (brute force). Using any lightweight proxy in front of your main web server is the solution if you are worried about large downloads linking web server resources.
It really depends on why you want to limit large downloads. If this saves users time, just add a messenger that indicates the maximum file size. If these are server resources, use a lightweight proxy in front of the server. If this is something else, well, what is it?
Cal
source share