note 73482 added to function.filesize
| From: | ibitgsm at gmail dot com | Date: | Sun, 25 Feb 2007 14:55:04 +0000 |
| Subject: | note 73482 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123854@lists.php.net to get a copy of this message | ||
Note that functions written in PHP which get directory size recursively are much slower than just
calling
du.
I hope this short code snipet will help someone:)
<?php
function dirsize($path)
{
$old_path = getcwd();
if(!is_dir($old_path."/".$path)) return -1;
$size = trim(shell_exec("cd \"".$old_path."/".$path."\"; du
-sb; cd \"".$old_path."\";"), "\x00..\x2F\x3A..\xFF");
return $size;
}
P.S. trim() remove here all nonprintable an non-digit chars which appear in the output of
du
?>
----
Server IP: 195.136.184.34
Probable Submitter: 83.24.247.50
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- https://master.php.net/note/edit/73482
Del: integrated -- https://master.php.net/note/delete/73482/integrated
Del: useless -- https://master.php.net/note/delete/73482/useless
Del: bad code -- https://master.php.net/note/delete/73482/bad+code
Del: spam -- https://master.php.net/note/delete/73482/spam
Del: non-english -- https://master.php.net/note/delete/73482/non-english
Del: in docs -- https://master.php.net/note/delete/73482/in+docs
Del: other reasons-- https://master.php.net/note/delete/73482
Reject -- https://master.php.net/note/reject/73482
Search -- https://master.php.net/manage/user-notes.php