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!

Link to comment
Share on other sites

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");

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.