PHP获取当前磁盘的总容量与剩余空间
该应用用到了PHP的自带函数
disk_total_space 获取磁盘的容量
disk_free_space 获取磁盘的剩余空间
<?php
//PHP获取磁盘大小
function get_disk_total(int $total) : string
{
$config = [
'3' => 'GB',
'2' => 'MB',
'1' => 'KB'
];
foreach($config as $key => $value){
if($total > pow(1024, $key)){
return round($total / pow(1024,$key)).$value;
}
return $total . 'B';
}
}
//
echo '当前磁盘的总容量:' . get_disk_total(disk_total_space('.'));
echo '<hr/>';
echo '当前磁盘的剩余空间:' . get_disk_total(disk_free_space('.')) ;