-
-
-
-
-
-
- function dirsize($dir)
- {
- @$dh = opendir($dir);
- $size = 0;
- while ($file = @readdir($dh))
- {
- if ($file != "." and $file != "..")
- {
- $path = $dir."/".$file;
- if (is_dir($path))
- {
- $size += dirsize($path);
- }
- elseif (is_file($path))
- {
- $size += filesize($path);
- }
- }
- }
- @closedir($dh);
- return $size;
- }
-
-
-
- $dir_path = "./my_files";
- $dir_size = dirsize($dir_path);
- $dir_size = $dir_size/1024/1024;
- echo $dir_size."MB";
- ?>
这个函数可以递归遍历目录中的所有文件,并计算以MB为单位的文件总大小。
新手出招,大佬们见笑了。
http://www.bkjia.com/PHPjc/729851.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/729851.htmlTechArticle? /** 统计目录文件大小的函数 @authorxfcode @linkhttp://www.jbxue.com */ functiondirsize($dir) { @$dh =opendir($dir); $size= 0 ; while ($file= @readdir ($dh)) { if ($file...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn