note 61753 added to function.filesize

From: Date: Fri, 10 Feb 2006 23:58:56 +0000
Subject: note 61753 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-103475@lists.php.net to get a copy of this message
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. ---- Server IP: 64.71.164.2 Probable Submitter: 67.181.154.141 ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61753 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61753&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61753&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61753&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61753&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61753&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61753&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61753&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61753&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103475) next »