Last active
April 4, 2017 13:17
-
-
Save mocanuga/77a0fdc5ede17eefed51f0b328ae9763 to your computer and use it in GitHub Desktop.
How to return the size of directory even if the directory is symlink with PHP?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author mocanuga | |
* @desc Return the size of directory in bytes. Tested on CentOS 5.11 Final | |
* @return int | |
*/ | |
function getFolderSize($folder = '') { | |
if(empty($folder)) | |
return -1; | |
$dir = escapeshellcmd($folder); | |
if(!is_dir($dir)) | |
return -1; | |
$cmd = is_link($dir) ? `du -sb $(readlink -f $dir)` : `du -sb $dir`; | |
$res = explode("\t", $cmd); | |
return (int)array_shift($res); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment