Solved

Detect Max File size available

Posted on 2006-06-28
4
201 Views
Last Modified: 2013-12-12
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();

Thanks
Mark
0
Comment
Question by:msiedle
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Khanh Doan
ID: 17006607
you can run phpinfo();
and then find : upload_max_filesize

Bonmat86.
0
 
LVL 2

Author Comment

by:msiedle
ID: 17006622
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 ...is 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?

Cheers,
Mark

0
 
LVL 10

Accepted Solution

by:
Khanh Doan earned 250 total points
ID: 17006686
<?php
$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;
?>

Bonmat86.
0
 
LVL 2

Author Comment

by:msiedle
ID: 17007075
Beautiful ...works great! Thank you :-))

Mark
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Php Array Diff 3 27
Install MySQL 5.6 and PHP on Centos Linux 6 51
resizeing PHP image 2 22
Not needed 13 55
This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now