PHP obtains the folder size function usage instance. PHP getting folder size function usage example this article describes PHP getting folder size function usage. Share it with you for your reference. The details are as follows :? Getting folder size f PHP getting folder size function usage example
This example describes how to use PHP to obtain the folder size function. Share it with you 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 ('directory to be retrieved size '));
?>
I hope this article will help you with php programming.
Examples in this article describes how to use PHP to obtain the folder size function. Share it with you for your reference. The details are as follows :? // Get the folder size f...