<?PHP/** Get the remaining space on a disk * $param associative array, the subscript is which disk, unit, can be B,KB,MB,GB * can be set to get multiple disks, for example: Array (' C ' = = ' KB ', ' D ' = = ' mb ', ' E ' + ' GB ') ' F ' = ' B ') * If there is an error, return false*/ functionSpace ($arr){ //Check Parameters if(Is_array($arr)){ //Initialize stored values $memory=Array(); foreach($arr as $disk=$size){ $D=Strtoupper($disk).‘:‘;//keyboard path converted to uppercase $S=Strtoupper($size);//units converted to uppercase 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:return0; Break; } }Else{ return NULL; } } return $memory; }Else{ return NULL; } } $arr=Array(' c ' = ' = ' kb ', ' d ' = ' Mb ', ' e ' = ' Gb ', ' f ' = ' Tb '); Var_dump(Space ($arr));
Get the free space function for a Windows disk