note 15342 deleted from function.filesize by jimw

From: Date: Fri, 14 Dec 2001 20:17:36 +0000
Subject: note 15342 deleted from function.filesize by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22720@lists.php.net to get a copy of this message
Here there's my function used for writing size in human format :) I think it's lighter than the one written above. function humansize($size) { $n = 0; while (($size > 1024) and ($n < 3)) { $size /= 1024; $n++; } if ($size - floor($size) == 0) $size = (int) $size; else $size = round($size,2); switch ($n) { case 0: return $size."B"; break; case 1: return $size."KB"; break; case 2: return $size."MB"; break; default: return $size."GB"; break; } } and if you are looking for a function that calculates the size of a directory, including all subdirectories and files, look at this: function dirsize($dir) { $dh = opendir($dir); $size = 0; while (($file = readdir($dh)) !== false) if ($file != "." and $file != "..") { $path = $dir."/".$file; if (is_dir($path)) $size += dirsize($path); elseif (is_file($path)) $size += filesize($path); } closedir($dh); return $size; } Let's enjoy them ! Federico

« previous php.notes (#22720) next »