note 61753 deleted from function.filesize by betz

From: Date: Sat, 11 Feb 2006 00:15:34 +0000
Subject: note 61753 deleted from function.filesize by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-103478@lists.php.net to get a copy of this message
Note Submitter: ---- I have programmed a really nice program that remotely lets you manage files as if you have direct access to them (http://sourceforge.net/projects/filemanage/). I have a bunch of really handy functions to do just about anything to files or directories. This function may be a bit more bulky than others posted here, but I use this in my program for both byte and bit messured files. I do media files which have bit rates so I need dividers which aren't 1024. It also only goes from byte (bit) to Gigabytes (gibabits) because anything larger than two gigabytes on a HTTP server is all but worthless on most server types. Here is the function I made; it may need some tweaking to work for your specific needs. <?PHP // function returns a string of the filesize with proper denominator // returns false if number is not greater than 0 or $size does not contain // numbers // str 'formmated file size' filesz( int 'number in bytes' [, bool 'is bytes?' [, int 'number of decimal places' ]] ) function filesz($size, $bytes = true, $decs = 2){ $size += 0; // set to int (since settype() doesn't seem to work correctly always) if($size >= 0){ if($bytes){ if($size < 980) return $size . ' bytes'; else if($size < 1000000) return round($size / 1024, $decs) . ' KB'; else if($size < 1020000000) return round($size / 1048576, $decs) . ' MB'; else return round($size / 1073741824, $decs + 1) . ' GB'; } else { if($size < 1000) return $size . ' bits'; else if($size < 1000000) return round($size / 1000, $decs) . ' Kb'; else if($size < 1000000000) return round($size / 1000000, $decs) . ' Mb'; else return round($size / 1000000000, $decs + 1) . ' Gb'; } } return false; } // end of filesz() ?> This function is in 0.9.7 (the current release of File Manage). Hope this helps some people.

« previous php.notes (#103478) next »