note 15342 added to function.filesize

From: Date: Thu, 06 Sep 2001 10:52:21 +0000
Subject: note 15342 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-17717@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 http://www.php.net/manual/it/function.filesize.php

« previous php.notes (#17717) next »