Solved

Detect Max File size available

Posted on 2006-06-28
4
203 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php email 2 26
Saving image into server to get url later 1 31
What is the best PDF generator to use? 1 28
Method for submitting dynamically created rows 20 16
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

910 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

18 Experts available now in Live!

Get 1:1 Help Now