Lonelydreamer Posted December 18, 2004 Posted December 18, 2004 Does anyone know of a way to get the size of a directory with the use of a PHP function? I found a fliesize function but I don't know if that works with drectories too. Quote
TCH-Dick Posted December 18, 2004 Posted December 18, 2004 I found this www.alt-php-faq.org/local/25/ but it's lacking an interface so I changed it to include a form. If you need it for a purpose other than what I did with it then you can just use the original. ><form action="" method="post" name="form1"> <p>Enter Directory Name - Leave empty for a listing of directories </p> <p> <input name="directory" type="text" id="directory"> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> <?php $totalsize=0; function show_dir($dir, $pos=2){ global $totalsize; if($pos == 2) echo "<hr><pre>"; $handle = @opendir($dir); while ($file = @readdir ($handle)){ if (eregi("^\.{1,2}$",$file)) continue; if(is_dir($dir.$file)){ echo "|- ".$pos."s <b>$file</b>\n"; show_dir("$dir.$file/", $pos+3); }else{ $size=filesize($dir.$file); echo "|- ".$pos."s $file "; echo("$size <br>"); $totalsize=$totalsize+$size; } } @closedir($handle); if($pos == 2) echo "</pre><hr>"; return($totalsize); } $totalsize = show_dir("/home/cpanelusername/public_html/$directory/"); echo($totalsize); ?> Quote
xzone9 Posted December 30, 2004 Posted December 30, 2004 That is an awesome script. Valuable and can be broken down for just whole directory size, etc. Thanks for the code snippet! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.