Detect Max File size available

Hi all

Is there a way to use PHP to detect the max file size available for file uploads on the server, as apposed to me setting it manually only to find that large uploads get cut off at a certain size?

Eg. I just want to run something like this:

$file_size = get_server_maxfilesize();

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Khanh DoanSenior DeveloperCommented:
you can run phpinfo();
and then find : upload_max_filesize

msiedleAuthor Commented:
Yea but i don't want to set it manually in code ...I want my script to be smart enough to be able to detect it depending on what server it's on that possible?

I know you can do:
ini_get( 'upload_max_filesize' )

...but that returns a value like '2M' (meaning 2 Meg) ...I'd need a value returned in full byte form. ie. 2097152

Any ideas?


Khanh DoanSenior DeveloperCommented:
$mfsize = ini_get('upload_max_filesize');

if ($pos = strpos($mfsize, 'M') != '')
      $size = substr($mfsize, 0, $pos);
      $fsize = $size * 1024 * 1024;
elseif  ($pos = strpos($mfsize, 'K') != '')
      $size = substr($mfsize, 0, $pos);
      $fsize = $size * 1024;

echo $fsize;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
msiedleAuthor Commented:
Beautiful great! Thank you :-))

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.