Hello
I want to write a script that gets the size of a folder. I tried:
disk_total_space( "../~test" ) but it didn't work. it just shows the total space on the disk which is not what I want.
I want to get the information about a folder only.
can somebody help please?
Thanks
How to get folder size?
Moderator: General Moderators
-
mcog_esteban
- Forum Contributor
- Posts: 127
- Joined: Tue Dec 30, 2003 3:28 pm
see if this helps:
Code: Select all
<?php
function dir_size($dir)
{
global $total;
print(\"\n\");
//check if file,dir exists
if(file_exists($dir))
{
// open directory
$myDirectory = dir($dir);
// get each entry
while(FALSE !== ($entryName = $myDirectory->read()))
{
if($entryName != \".\" && $entryName != \"..\")
{
if(is_dir($dir.$entryName))
{
$dirs[] = $entryName;
}
else
{
// get name and file size
$name = $entryName;
$size = filesize($dir.$entryName);
//add file size
$total += $size;
}
}
}
// close directory
$myDirectory->close();
}
//there's sub dir's ?
if(count($dirs) != 0)
{
foreach($dirs as $key => $value)
{
//do the same for each sub dir
dir_size($dir.$value.\"/\");
}
}
}
$total = 0;
dir_size(\"./\");
echo number_format($total).\" bytes\";
?>