note 73482 deleted from function.filesize by danbrown

From: Date: Sun, 18 Jan 2009 18:07:27 +0000
Subject: note 73482 deleted from function.filesize by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149409@lists.php.net to get a copy of this message
Note Submitter: ibitgsm at gmail dot com ---- 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 ?>

« previous php.notes (#149409) next »