note 37402 deleted from configuration.directives by nlopess

From: Date: Sun, 27 Jun 2004 09:42:46 +0000
Subject: note 37402 deleted from configuration.directives by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71867@lists.php.net to get a copy of this message
Note Submitter: Chris DeRose ---- 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; } }

« previous php.notes (#71867) next »