Marius van Witzenburg We fight for our survival, we fight!

14Jun/110

How to get the maximum upload file size possible in PHP

Lets say you build websites for different servers the chance that the maximum upload size differs on these servers might be big. So, you want to automatically handle this.

In the following example we simply get the sizes who have influence on the maximum upload possible. Note that you can set the upload_max_filesize to a really big value but you still need memory to handle the file in most cases!

With the following example you can get the lowest possible value and use that in your script to handle as upload maximum.

$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);
echo $upload_mb;

This example gets the value in MegaBytes.

Posted by mariusvw

Reacties (0) Trackbacks (0)

Nog geen reacties


Leave a comment

(required)

Nog geen trackbacks.