note 37402 added to configuration.directives

From: Date: Thu, 13 Nov 2003 19:08:15 +0000
Subject: note 37402 added to configuration.directives
Groups: php.notes 
Request: Send a blank email to php-notes+get-60351@lists.php.net to get a copy of this message
Alan, I was in need of a function that would tell me what the actual size was of the 'post_max_size' and the 'upload_max_filesize' , in bytes. I played around with the php.ini file a good deal and I was able to ascertain: * The letters B,K, & M are valid desigations for the unit types (G is definately not supported and so I will presume neither is t,p or anything larger than that) * Not specifying a unit type is a valid setting for these parameters and that the parser defaults to byte-units for these settings With this in mine, here's my inisize_to_bytes() function which does what the function's name would imply. Note that I'm casting the numeric values as doubles b/c integers can only hold some roughly 2 billion bytes which would mean this function could only convert values lower than (approximately) 1907.3 megabytes. (Does anyone care to verify my math here for me?) I doubt anyone is handling POST requests or files that large through http , but in my case I'll be using this function to parse other values than will be found in the php.ini. Here goes: function inisize_to_bytes ( $strIniSize ) { // This function will take the string value of an ini 'size' parameter, // and return a double (64-bit float) representing the number of bytes that the parameter represents. Or false if $strIniSize is unparseable. $a_IniParts = array(); if (!is_string( $strIniSize )) return false; if (!preg_match ('/^(\d+)([bkm]*)$/i', $strIniSize,$a_IniParts)) return false; $nSize = (double) $a_IniParts[1]; $strUnit = strtolower($a_IniParts[2]); switch($strUnit) { case 'm': return ($nSize * (double) 1048576); case 'k': return ($nSize * (double) 1024); case 'b': default: return $nSize; } } ---- Manual Page -- http://www.php.net/manual/en/configuration.directives.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37402 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37402&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37402&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60351) next »