File uploading normally requires client validation (mainly as a UI improvement) and server validation (in case the client validation is bypassed/hacked).
<input type="hidden" name="MAX_FILE_SIZE" value="2621440"/>
The idea is accessing the
files JS property of the input field and read the file size on the ‘change’ event (when a file is selected from the user). If the selected files exceeds the max size, I simply display a clear user warning and disable the
submit button. I’ve created a generic script that automatically listens to the
change event for any file upload element, and reads the max upload size in bytes from the
MAX_FILE_SIZE HTML input hidden element in the same form.
Server side validation (PHP)
Just set the desidered value for ‘upload_max_filesize’ and ‘post_max_size’ PHP settings (php.ini). Alternatively, if you need application specific settings and you use apache as webserver, add the following lines into the
.htaccess in your webroot
php_value upload_max_filesize 25M php_value post_max_size 25M