There are times when you need to get disk space usage in normal programming, and most of the time you use the Disk_free_space and Disk_total_space functions.
The following example is to obtain the server all disk space size, the example is as follows:
/**
* Byte formatting converts the size of the byte number format to the B K M G T P E Z Y Description
* @param int $size size
* @param int $DEC Display Type
* @return int
*/
function Byte_format ($size, $dec =2)
{
$a = Array ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
$pos = 0;
while ($size >= 1024)
{
$size/= 1024;
$pos + +;
}
Return round ($size, $dec). " ". $a [$pos];
}
/**
* Obtain individual disk information
* @param $letter
* @return Array
*/
function Get_disk_space ($letter)
{
Get disk information
$DISKCT = 0;
$disk = Array ();
/*if (@disk_total_space ($key)!=null) * To prevent the server from being affected, do not check the floppy drive
{
$DISKCT = 1;
$disk ["A"]=round ((@disk_free_space ($key)/(1024*1024*1024)), 2). " G/". Round ((@disk_total_space ($key)/(1024*1024*1024), 2). ' G ';
}*/
$diskz = 0; Total disk capacity
$DISKK = 0; Disk remaining capacity
$is _disk = $letter. ': ';
if (@disk_total_space ($is _disk)!=null)
{
$diskct + +;
$disk [$letter][0] = Byte_format (@disk_free_space ($is _disk));
$disk [$letter][1] = Byte_format (@disk_total_space ($is _disk));
$disk [$letter][2] = Round (((@disk_free_space ($is _disk)/(1024*1024*1024)/(@disk_total_space ($is _disk)/(1024*1024 *1024)) *100,2). ' %';
$DISKK +=byte_format (@disk_free_space ($is _disk));
$diskz +=byte_format (@disk_total_space ($is _disk));
}
return $disk; Www.2cto.com
}
/**
* Get disk usage
* @return var
*/
function Get_spec_disk ($type = ' system ')
{
$disk = Array ();
Switch ($type)
{
Case ' system ':
Strrev (Array_pop (Explode (': '), Strrev (Getenv_info (' SystemRoot '))));//Get system drive letter
$disk = Get_disk_space (Strrev (Array_pop (Explode (': '), Strrev (getenv (' SystemRoot '))));
Break
Case ' all ':
foreach (Range (' B ', ' Z ') as $letter)
{
$disk = Array_merge ($disk, Get_disk_space ($letter));
}
Break
Default
$disk = Get_disk_space ($type);
Break
}
return $disk;
}
This allows you to expand your disk, such as getting the overall disk space size, the remaining space on the disks.
Here also have to re-explain, if the server has a floppy disk remember to avoid, otherwise the server-related floppy disk running program has a fixed obstacle, using the program to read all disk usage may be slow! Attention!
http://www.bkjia.com/PHPjc/478578.html www.bkjia.com true http://www.bkjia.com/PHPjc/478578.html techarticle There are times when you need to get disk space usage in normal programming, and most of the time you use the Disk_free_space and Disk_total_space functions. The following instance is the GET server all disk empty ...