note 86756 deleted from function.filesize by danbrown

From: Date: Sun, 02 Nov 2008 14:47:38 +0000
Subject: note 86756 deleted from function.filesize by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146045@lists.php.net to get a copy of this message
Note Submitter: luruke ---- My filesize parser: <?php define("SCALE", 1024); $file = $argv[1] or die("No input file.\n"); if(!__exist($file)) die("File doesn't exist.\n"); function __exist($file){ return ((@fopen($file, "r")) ? true : false); } function __strlen($text){ $i=0; while($text[$i]) $i++; return $i; } function __round($float, $offset){ $float = (string) $float; for($temp='', $dot=false, $i=0; $i<__strlen($float); $i++){ if($dot) $offset--; if($float[$i] == ".") $dot = true; $temp .= $float[$i]; if($offset == 0) break; } return (float) $temp; } function __pow($base,$exp){ if($exp==0) return 1; for($temp=$base,$i=1; $i<$exp; $i++) $base *= $temp; return $base; } function __parse($bytes){ $types = array("Bytes","Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"); for($i=0; $i<count($types); $i++){ if($bytes < __pow(SCALE,$i+1)){ return __round($bytes/__pow(SCALE,$i),2).$types[$i]; } } } print __parse(filesize($file))."\n"; ?>

« previous php.notes (#146045) next »