Page 1 of 1

convert file sizes like "10M"

Posted: Sun Nov 27, 2005 5:00 pm
by djot
-
Hi,


Is there a function that may convert file size information like "10M" to the according size in bytes?



besides:
My uploads fail, because I do set the hidden field with a value I get via ini_get('upload_max_filesize'). ini_get returns "10M" instead of 10485760 (bytes).

Code: Select all

$form = '<input type="hidden" name="MAX_FILE_SIZE" value="'.ini_get('upload_max_filesize').'" />';

djot
-

Posted: Sun Nov 27, 2005 5:07 pm
by Jenk
You could always enter the value manually, or if the php.ini is always going to have the value in Megabytes:

Code: Select all

<?php

function meg2byte ($val) {
    return ((intval($val) * 1024) * 1024);
}

echo meg2byte('10M');

?>

Posted: Sun Nov 27, 2005 5:21 pm
by Weirdan
well, it has been discussed in the manual: http://us2.php.net/manual/en/function.i ... #AEN136763

Posted: Sun Nov 27, 2005 6:04 pm
by djot
-
Thanks,

I only did read all "upload" related posts on php.net. Thanks. Anyway I think php should recognize "10M" as the right size in byte itself, rather than I have to convert it. And no, I do not know if php.ini returns always "10M" because I don't know all the servers the script runs on for sure.


djot
-