note 77900 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Sat, 02 May 2009 11:16:47 +0000 |
| Subject: | note 77900 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154116@lists.php.net to get a copy of this message | ||
Note Submitter: hkpark99 at dreamwiz dot com
----
How to get folder size? Here is an answer.
<?php
function foldersize($path) {
$total_size = 0;
$files = scandir($path);
foreach($files as $t) {
if (is_dir($t)) { // In case of folder
if ($t<>"." && $t<>"..") { // Exclude self and parent
folder
$size = foldersize($path . "/" . $t);
// print("Dir - $path/$t = $size<br>\n");
$total_size += $size;
}
}
else { // In case of file
$size = filesize($path . "/" . $t);
// print("File - $path/$t = $size<br>\n");
$total_size += $size;
}
}
return $total_size;
}
?>