Home > Backend Development > PHP Tutorial > PHP Get Folder Size Function Usage Example_PHP Tutorial

PHP Get Folder Size Function Usage Example_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:47:46
Original
966 people have browsed it

PHP Get Folder Size Function Usage Example

This article describes the example of PHP Get Folder Size function usage. Share it with everyone for your reference. The details are as follows:

 ?

// Get the folder size

Function getDirSize($dir)

 {

$handle = opendir($dir);

While (false!==($FolderOrFile = readdir($handle)))

 {

 if($FolderOrFile != "." && $FolderOrFile != "..")

 {

 if(is_dir("$dir/$FolderOrFile"))

 {

$sizeResult = getDirSize("$dir/$FolderOrFile");

 }

else

 {

$sizeResult = filesize("$dir/$FolderOrFile");

 }

 }

 }

closedir($handle);

return $sizeResult;

 }

// Automatic unit conversion function

Function getRealSize($size)

 {

 $kb = 1024; // Kilobyte

 $mb = 1024 * $kb; // Megabyte

 $gb = 1024 * $mb; // Gigabyte

 $tb = 1024 * $gb; // Terabyte

 if($size < $kb)

 {

return $size." B";

 }

else if($size < $mb)

 {

return round($size/$kb,2)." KB";

 }

else if($size < $gb)

 {

return round($size/$mb,2)." MB";

 }

else if($size < $tb)

 {

return round($size/$gb,2)." GB";

 }

else

 {

Return round($size/$tb,2)." TB";

 }

 }

echo getRealSize(getDirSize('The directory whose size needs to be obtained'));

 ?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1025335.htmlTechArticlePHP Get Folder Size Function Usage Example This article describes the usage of PHP Get Folder Size function. Share it with everyone for your reference. The details are as follows: ? // Get the folder size f...
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template