disk usage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaurav_sting
Forum Newbie
Posts: 19
Joined: Sat Mar 27, 2004 3:45 am
Location: Delhi

disk usage

Post 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
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post 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
Post Reply