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
Solved

Detect Max File size available

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

790 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