note 41185 added to function.filesize

From: Date: Fri, 02 Apr 2004 02:12:22 +0000
Subject: note 41185 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-67498@lists.php.net to get a copy of this message
All the other functions I see on this page are just bloated if else statements, this is a nice and neat function that will calculate all the way up to EB and more if you add them to the array $sizes. function DownloadSize($file) { $size = filesize($file); $sizes = Array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'); $ext = $sizes[0]; for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; } return round($size, 2).$ext; } ---- http://www.spacevs.com/index.php?page=phpsnippets ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41185 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41185&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41185&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67498) next »