Page 1 of 1

disk usage

Posted: Mon Jun 07, 2004 8:58 am
by gaurav_sting
hi everyone,

i am stuck in a situation, kindly help.

i am making a system in which there is multiple login (just like yahoo mail), now fixed disk quota has been assigned to the users (5 mb), users are allowed to upload certain images in their respective folders. now i want that the total size of the folder does not exceed the 5 mb limit. how can i know that user's folder has occupied n number of bytes or n number or MB of space.

i want to show to the user that - you have consumed this much % of space, just like yahoo mail shows.

Thanks
Gaurav

Posted: Mon Jun 07, 2004 9:31 am
by Saethyr
php.net!

know it
love it
live it!

Code: Select all

<?php
function dir_size($dir) {
   $totalsize=0;
   if ($dirstream = @opendir($dir)) {
       while (false !== ($filename = readdir($dirstream))) {
           if ($filename!="." && $filename!="..")
           {
               if (is_file($dir."/".$filename))
                   $totalsize+=filesize($dir."/".$filename);
               
               if (is_dir($dir."/".$filename))
                   $totalsize+=dir_size($dir."/".$filename);
           }
       }
   }
   closedir($dirstream);
   return $totalsize;
} 
?>
edited, found a recursive one