<?php /* *獲取某個磁盤的剩余空間 *$param 關聯數組,下標是哪個盤,單位,可以是B,KB,MB,GB *可以設置獲取多個磁盤,例如:array('C'=>'KB','D'=>'MB','E'=>'GB','F'=>'B') *假如出錯,返回false */ function Space($arr){ //檢查參數 if(is_array($arr)){ //初始化存儲值 $memory = array(); foreach($arr as $disk=>$size){ $D = strtoupper($disk).':';//轉化為大寫的鍵盤路徑 $S = strtoupper($size);//轉變為大寫的單位 if(in_array($D,array('C:','D:','E:','F:')) && in_array($S,array('B','KB','MB','GB','TB'))){ switch($S){ case 'B': $memory[$disk]= disk_free_space($D).'B'; break; case 'KB': $d = round(disk_free_space($D) / 1024); $memory[$disk] = $d .'KB'; break; case 'MB': $d = round(disk_free_space($D) / pow(1024,2)); $memory[$disk]= $d.'MB'; break; case 'GB': $d = round(disk_free_space($D) / pow(1024,3)); $memory[$disk]= $d.'GB'; break; case 'TB': $d = sprintf("%.4f", disk_free_space($D) / pow(1024,4)); $memory[$disk] = $d .'TB'; break; default: return 0; break; } }else{ return null; } } return $memory; }else{ return null; } } $arr = array('c'=>'kb','d'=>'Mb','e'=>'Gb','f'=>'Tb'); var_dump(Space($arr));