How can you get, the total size of a certain directory?
Answer Posted / suren
You can use the folowing function as shown in alt.php by
ryanflynnn at my-deja.com:
<?php
$totalsize=0;
function show_dir($dir, $pos=2){
global $totalsize;
if($pos == 2)
echo "<hr><pre>";
$handle = @opendir($dir);
while ($file = @readdir ($handle)){
if (eregi("^\.{1,2}$",$file))
continue;
if(is_dir($dir.$file)){
echo "|- ".$pos."s <b>$file</b>\n";
show_dir("$dir.$file/", $pos+3);
}else{
$size=filesize($dir.$file);
echo "|- ".$pos."s $file ";
echo("$size <br>");
$totalsize=$totalsize+$size;
}
}
@closedir($handle);
if($pos == 2) echo "</pre><hr>";
return($totalsize);
}
$totalsize = show_dir("c:/winnt/system32/");
echo($totalsize);
?>
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What are the design patterns in php?
How to set session.gc_divisor properly?
How to create a session? How to set a value in session? How to remove data from a session?
What’s the difference between htmlentities() and htmlspecialchars()?
What is php rest api?
How to pass an argument to a function?
Which function is used in php to delete a file?
What is the ioncube php loader?
What is framework? How it works? What is advantage?
How do I use isdigit function?
Can we extend final class in php?
What is php key?
Does php have multiple inheritance?
How many ways to include variables in double-quoted strings in php?
What is $_ request?