Hello,

I have created a script and as part of the script i want the script to detect the upload_max_filesize which is set in the web servers php.ini file. It will be displayed on the file upload webpage which is accessible to admins only.

Now at the moment i am using:

# Warn user the max filesize
$SiteInfoMessages =
'<b>Note:</b> <br />
We have detected that <b>your</b> web host does not allow you to upload any file
greater than <b>' . ini_get('upload_max_filesize') . '</b>.
If you try and upload a file larger than <b>'. ini_get('upload_max_filesize') .'</b>;
the upload will fail.';

# display max filesize
echo $SiteInfoMessages;

As my script is going to be freely shared i want to know will this work on all web hosts and windows hosting? obviously php has to be installed but heard that web hosts can block the checking of a php.ini file. If i am likely to have problems with this with some webhosts can anyone recommend how would i go about detecting the upload_max_filesize in the php.ini file.

I was thinking of an if statement but not sure how the condition would be written as not sure what php function would do the trick plus not sure if i would have any problems with the above code on some web hosts.

Thanks for any help/suggestions.

PHPLOVER

here is the best way for displaying max upload in mB

$max_upload = (int)(ini_get('upload_max_filesize'));
$max_post = (int)(ini_get('post_max_size'));
$memory_limit = (int)(ini_get('memory_limit'));
$upload_mb = min($max_upload, $max_post, $memory_limit);

$upload_mb is the maximum upload size and the smallest of the three.

just use an if ($upload_mb && $upload_mb != 0)
else display an error 'unknown max file size<br />Please contact your system administrator for assisstance'

or something like that

Hi,

Thank you for your help. :)

PHPLOVER

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.