Directory Size
By: Daniel
Creating a script to display the size of a directory is fairly simple. First off you need to know the path to the directory. After that is known you can use the following fuction to display the filesize:
function dirsize($dir) { $dirs = array($dir); while(!empty($dirs)) { // Loop through all directories $path = array_shift($dirs); foreach(glob($path.'/*') AS $next) { if(is_dir($next)) { $dirs[] = $next; // Add another directory to the loop } else { $size += filesize ($next); // Add filesize to count } } } return $size; // Return the total filesize of the directory }
This function returns a string with the size of the directory in bytes. You can however use the Convert byte count function to produce a readable format.
An example of this code could be:
$path = '.'; echo dirsize($path); // would produce something like 732952 or 715.79 KB using the Convert byte count function





















March 3rd, 2007 at 7:33 am
Do I have to be a member to post to this blog?
March 19th, 2007 at 3:24 pm
Thanks alot webmaster I like your site
June 15th, 2011 at 4:24 am
Je voulais juste dire thème aweseome et post.I grande comme la façon dont vous Wright. Avez-vous pensé de l’écriture freelance?
July 29th, 2011 at 4:15 am
News is a great thing.
August 28th, 2011 at 3:42 pm
I have read several excellent stuff here. Definitely worth bookmarking for revisiting. I wonder how much attempt you put to create this kind of fantastic informative web site.
November 14th, 2011 at 2:33 pm
I have discovered that clever real estate agents just about everywhere are getting set to FSBO Marketing and advertising. They are acknowledging that it’s not just placing a sign post in the front property. It’s really regarding building relationships with these sellers who at some point will become consumers. So, after you give your time and energy to serving these retailers go it alone – the “Law of Reciprocity” kicks in. Thanks for your blog post.
November 14th, 2011 at 3:42 pm
It’s actually a great and helpful piece of info. I’m happy that you shared this useful information with us. Please stay us up to date like this. Thank you for sharing.
November 16th, 2011 at 12:16 am
How do I start blogging and make money at the same time?