note 57745 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 09 Nov 2005 06:15:59 +0000 |
| Subject: | note 57745 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98307@lists.php.net to get a copy of this message | ||
Note Submitter: mindhacker @ aol (sucks, i know) dot com
----
I stole this from above, but modified it to return the *full recursive size* of all files in the
directory.
<?php
// $path : path to browse
// $d : must not be defined
function searchdir ( $path , $d = 0, $totalsize=0 )
{
if ( substr ( $path , strlen ( $path ) - 1 ) != '/' ) { $path .= '/' ; }
$dirlist = array () ;
if ( $handle = opendir ( $path ) )
{
while ( false !== ( $file = readdir ( $handle ) ) )
{
if ( $file != '.' && $file != '..' )
{
$file = $path . $file ;
if ( ! is_dir ( $file ) ) {
$totalsize=$totalsize+filesize($file);
}
elseif ( $d >=0)
{
$totalsize=$totalsize+searchdir ( $file . '/' , $d + 1) ;
}
}
}
closedir ( $handle ) ;
}
return ( $totalsize ) ;
}
?>