Jump to content
Sign in to follow this  

Directory Size?

Recommended Posts

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.

Share this post

Link to post
Share on other sites

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>
   <input name="directory" type="text" id="directory">
   <input type="submit" name="Submit" value="Submit">


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)) 
       echo "|- ".$pos."s <b>$file</b>\n"; 
       show_dir("$dir.$file/", $pos+3); 
       echo "|- ".$pos."s $file "; 
       echo("$size <br>"); 

   if($pos == 2) echo "</pre><hr>"; 


$totalsize = show_dir("/home/cpanelusername/public_html/$directory/"); 

Share this post

Link to post
Share on other sites

That is an awesome script. Valuable and can be broken down for just whole directory size, etc. Thanks for the code snippet!

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...