Jump to content

Directory Size?


Recommended Posts

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); 
?>

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

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

Guest
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.

 Share

×
×
  • Create New...