Jump to content

Getting the size of a folder (contents) when nothing has worked...


anolan13

Recommended Posts

Hello all,

 

All Ive been trying to do is make a short php script (embedded in the html, no separate file) that simply displays how much space, in megabytes, the contents of a certain folder is taking and use an echo command to display it. I've tried the filesize command and it always gives me 4,096 regardless of the contents. I assume this is because PHP is taking the size of the actual folder. I've tried disk_total_space but this displays a number that is completely off.

 

I know this shouldn't be this hard. Any help is greatly appreciated.

 

 

Thanks!

try somthing like:

 

exec("du -s *", $output);
$var = arraytostring($output);
$newoutput = explode("\t", $var);
for($a=0;$a < count($newoutput);$a++ )
{
echo $newoutput[$a];
}

 

There is no such function as arraytostring().

 

If your using Linux, this function may help you.

 

<?php

    function getdirsize($dir) {
        exec("du -chs $dir | awk '{print $1}'", $out);
        return $out[1];

    }

    // example.
    echo getdirsize("/tmp");

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.