Solved

Detect Max File size available

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 four methods for overlaying images in a container on a web page
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 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