Hi,about file size

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lakshman
Forum Newbie
Posts: 1
Joined: Thu Aug 21, 2008 1:50 am

Hi,about file size

Post by lakshman »

Hi all,
i am new to Php.How to find folder size using php..
Plz help me
Regards,
Lakshmn
Corvin
Forum Commoner
Posts: 49
Joined: Sun Dec 03, 2006 1:04 pm

Re: Hi,about file size

Post by Corvin »

With a recursive function which uses filesize().

Example 1:

Code: Select all

<?php
$dir = "testFolder";
 
echo list_files($dir, 0);
 
function list_files($dir, $filesize) {
    $dirh = opendir($dir);
 
    while ( $file = readdir($dirh) ) {
        if ($file != "." && $file != ".." ) {
            if ( is_dir($dir ."/" .$file) ) {
                $filesize = list_files($dir ."/" .$file, $filesize);
            } else {
                $filesize += filesize($dir . "/" .$file);
            }
        }
    }
 
    closedir($dirh);
 
    return $filesize;
}
?>
Example 2:
:arrow: http://de3.php.net/manual/en/function.f ... .php#80995
Post Reply