Posted By

scopefragger on 09/07/09


insert php size new folders

Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


Find the size of a folder or directory

 / Published in: PHP


Ever wanted to give your cliant an idear on how much disk space they have remaining? The following script will tell your user how much disk space has been used and how much is remaining. In this example $diskspace refers the amount of diskspace your cliant has avalable.

The value of disk space can be changed to suite, if required this value can my connected to a mysql_query. Such as if you are running a hosting service, have the value pulled from your hosting database.

If you dont wish to include a /mb removed the "." MB / ". $diskspace" line 4

  1. <?
  2. $diskspace="30Mb";
  3. $path = $_SERVER['DOCUMENT_ROOT'];
  4. echo (filesize_r($path)/1048576)." MB / ". $diskspace;
  6. function filesize_r($path){
  7. if(!file_exists($path)) return 0;
  8. if(is_file($path)) return filesize($path);
  9. $ret = 0;
  10. foreach(glob($path."/*") as $fn)
  11. $ret += filesize_r($fn);
  12. return $ret;
  13. }
  14. ?>

Report this snippet  

You need to login to post a comment.