note 79564 added to ini.core
| From: | gilthans dot NO dot SPAM at gmail dot com | Date: | Mon, 03 Dec 2007 18:52:35 +0000 |
| Subject: | note 79564 added to ini.core | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132771@lists.php.net to get a copy of this message | ||
If you want to display the upload limit without knowing the server configuration, this may be
useful:
<?php
function let_to_num($v){ //This function transforms the php.ini notation for numbers (like
'2M') to an integer (2*1024*1024 in this case)
$l = substr($v, -1);
$ret = substr($v, 0, -1);
switch(strtoupper($l)){
case 'P':
$ret *= 1024;
case 'T':
$ret *= 1024;
case 'G':
$ret *= 1024;
case 'M':
$ret *= 1024;
case 'K':
$ret *= 1024;
break;
}
return $ret;
}
$max_upload_size = min(let_to_num(ini_get('post_max_size')),
let_to_num(ini_get('upload_max_filesize')));
echo "Maximum upload file size is ".($max_upload_size/(1024*1024))."MB.";
?>
Do note however that this limit is not completely reliable; there are other factors which need to be
taken into account, such as any other $_POST data and their size, the memory limit, and the script
time limit. This does, however, give some rough limit, and helps you avoid "Doh!" problems
where you can't figure out why your file won't upload. :)
----
Server IP: 82.80.248.162
Probable Submitter: 194.90.189.52
----
Manual Page -- http://www.php.net/manual/en/ini.core.php
Edit -- https://master.php.net/note/edit/79564
Del: integrated -- https://master.php.net/note/delete/79564/integrated
Del: useless -- https://master.php.net/note/delete/79564/useless
Del: bad code -- https://master.php.net/note/delete/79564/bad+code
Del: spam -- https://master.php.net/note/delete/79564/spam
Del: non-english -- https://master.php.net/note/delete/79564/non-english
Del: in docs -- https://master.php.net/note/delete/79564/in+docs
Del: other reasons-- https://master.php.net/note/delete/79564
Reject -- https://master.php.net/note/reject/79564
Search -- https://master.php.net/manage/user-notes.php