Page 1 of 1

problem : how to calculate disk space

Posted: Fri Dec 27, 2002 1:56 pm
by graziano
Hello,

which is the best way to calculate disk usage on a directory (and its subdirectory) using php without receing errors if a not readable dir is found ?

I tried to use @shell_exec() and @passthru with the linux command du , but if "du" find some not readable directory it reports error (and there is no way to hide it )

Code: Select all

<?
ob_start();
@passthru("/usr/bin/du -sk /home/test");
$spacea = ob_get_contents();
ob_end_clean();
$spaceb = ereg_replace ("/home/test", "", $spacea);
$spaceb = str_replace(' ','',$spaceb);
$spacec = $spaceb/1024;
$spaced = number_format($spacec, 3, ',', ' ');
?>



Thanks
Graz

Posted: Fri Dec 27, 2002 2:31 pm
by kcomer
I've had good luck using php's file system functions for this stuff. Haven't used it to calucltae the file sizes but there is a filsize function which should do the trick. Using readdir and readfile along with filesize you can make a script that reads all the files and folders and gets the sizes of each file, then just store the info in an array and do some calculations on it.