note 22201 added to function.filesize

From: Date: Mon, 10 Jun 2002 15:28:18 +0000
Subject: note 22201 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-31664@lists.php.net to get a copy of this message
This may come in handy for someone. Returns the size of the passed file in the appropriate measurement format. function my_filesize($file) { // First check if the file exists. if(!is_file("./".$file)) exit("File does not exist!"); // Setup some common file size measurements. $kb = 1024; // Kilobyte $mb = 1024 * $kb; // Megabyte $gb = 1024 * $mb; // Gigabyte $tb = 1024 * $gb; // Terabyte // Get the file size in bytes. $size = filesize($file); /* If it's less than a kb we just return the size, otherwise we keep going until the size is in the appropriate measurement range. */ if($size < $kb) { return $size." B"; } else if($size < $mb) { return round($size/$kb,2)." KB"; } else if($size < $gb) { return round($size/$mb,2)." MB"; } else if($size < $tb) { return round($size/$gb,2)." GB"; } else { return round($size/$tb,2)." TB"; } } -- http://www.php.net/manual/en/function.filesize.php http://master.php.net/manage/user-notes.php?action=edit+22201 http://master.php.net/manage/user-notes.php?action=delete+22201 http://master.php.net/manage/user-notes.php?action=reject+22201

« previous php.notes (#31664) next »