Solved

Detect Max File size available

Posted on 2006-06-28
4
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

695 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