I have this function below that is supposed to get the size of the directory and all of it's contents and echo the size back out. For some reason I get lots of odd errors and cant seem to get it right. Could someone please help me out or hook me up with a working script.
THANKS!
//get information
$username = $_SESSION['username@hosting.spechal.com'];
$dir = "/home/XXXXX/public_html/".$username."/";
echo spaceused($dir);
//set initial directory size
$total = 0;
//start function
function spaceused($dir){
global $total;
chdir($dir);
$username = $_SESSION['username@hosting.spechal.com'];
//if no user logged in kill script
if(!$username){ echo "Error, no user logged in!"; exit(); }
if(is_dir($dir)){
if($dh = opendir($dir)){
while(($file = readdir($dh)) !== FALSE){
//if it is finally determined it is a directory
//set the new dir and recall function
if(is_dir($dir.$file) && $file != "." && $file != ".."){
$dir = $dir.$file."/";
spaceused($dir);
} else {
//otherwise get the file size
chdir($dir);
$size = filesize($file);
//if size cant be determined, change the path and try again
if(!$size){ $file = $dir.$file;
$size = filesize($file); } else { $size = filesize($file); }
//set total size again
$total += $size;
} }
} }
//end of if's and loops
//convert kb into MB
$total /= 1048576;
$rounded = round($total, 1).' MB';
return $rounded;
//end of function
}
Sorry it looks so jumbled. 🙁