A PHP function that is a statistical directory file size,
Just came to the company in the morning, the head told me, grasp to write a small function, used to count the file size in the specified directory, I went, do it, fortunately a little foundation, a will be completed, haha. The code is below.
- /**
- Functions for Statistics directory file size
- @author Xfcode
- @link http://www.jbxue.com
- */
- 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;
- }
- Function end
- eg
- $dir _path = "./my_files";
- $dir _size = dirsize ($dir _path);
- $dir _size = $dir _size/1024/1024x768;
- Echo $dir _size. "MB";
- ?>
This function recursively iterates through all the files in the directory and calculates the total file size in megabytes.
Rookie moves, the big boys are laughed at.
http://www.bkjia.com/PHPjc/1084385.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084385.html techarticle A statistical directory file size PHP function, just came to the company in the morning, the head told me, hurry to write a small function, used to count the file size in the specified directory, I have a go, do it, okay ...