anolan13 Posted July 1, 2007 Share Posted July 1, 2007 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 https://forums.phpfreaks.com/topic/57933-getting-the-size-of-a-folder-contents-when-nothing-has-worked/ Share on other sites More sharing options...
clanstyles Posted July 1, 2007 Share Posted July 1, 2007 try somthing like: exec("du -s *", $output); $var = arraytostring($output); $newoutput = explode("\t", $var); for($a=0;$a < count($newoutput);$a++ ) { echo $newoutput[$a]; } Link to comment https://forums.phpfreaks.com/topic/57933-getting-the-size-of-a-folder-contents-when-nothing-has-worked/#findComment-287067 Share on other sites More sharing options...
trq Posted July 1, 2007 Share Posted July 1, 2007 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 https://forums.phpfreaks.com/topic/57933-getting-the-size-of-a-folder-contents-when-nothing-has-worked/#findComment-287070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.