note 77900 modified in function.filesize by danbrown

From: Date: Sun, 18 Jan 2009 18:04:32 +0000
Subject: note 77900 modified in function.filesize by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149402@lists.php.net to get a copy of this message
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; } ?> --was-- How to get folder size? Here is an answer. =========================================== 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; } http://php.net/manual/en/function.filesize.php

« previous php.notes (#149402) next »