PHP file upload max size is determined by 3 configuration values in php.ini, namely upload_max_filesize, post_max_size and memory_limit. You can get the maximum file size allowed in uploading by this snippet:
$max_upload = (int)(ini_get('upload_max_filesize'));
$max_post = (int)(ini_get('post_max_size'));
$memory_limit = (int)(ini_get('memory_limit'));
$upload_mb = min($max_upload, $max_post, $memory_limit);
Wherein $upload_mb is the maximum file size allowed for upload in MB. It’s the smallest of the 3 values. Just display this value beside the file upload control so the user knows the limit before choosing the file.
You should also read:
- How to bring down / optimize memory usage in your unmanaged Linux VPS box and avoid OOM (Out Of Memory) errors?
- Backup and recover a MySQL database under command line
- Check for file size with JavaScript before uploading
- Check how much memory your PHP script is using. (PHP script memory usage)
- CSS: Styling File Upload / Select Input Control <input type="file" … />


Facebook
Twitter
Google Plus
{ 4 comments… read them below or add one }
Great! Thanx :)
Thank you very much for this! Such a time saver.
From PHP manual:
Note: When querying memory size values
Many ini memory size values, such as upload_max_filesize, are stored in the php.ini file in shorthand notation. ini_get() will return *the exact string stored in the php.ini file* and NOT its integer equivalent. Attempting normal arithmetic functions on these values will not have otherwise expected results.
Since not everyone will use the same notation for all three values, it’s better to convert all of them to bytes first, before finding min value.
Nice Thanks!