$harddrive_out = format_bytes(kb2bytes($harddrive[2])).'<small> / '.format_bytes(kb2bytes($harddrive[1])).' <small>('.calculate_percentage(kb2bytes($harddrive[2]), kb2bytes($harddrive[1])).'% Free)</small></small>';
这行给出了错误
我从http://www.installgentoo.net/得到这个代码这显然对他们有用。我用的是windows,他们可能用的是linux
如果这是一个windows的问题,我怎么能做的东西,为windows和linux(总是得到正确的硬盘,所以我不使用像disk_total_space("C:")
的东西,因为所有的web服务器可能没有它在C驱动器。
如果你想要我使用的方法
function format_bytes($bytes){
if ($bytes < 1024){ return $bytes; }
else if ($bytes < 1048576){ return round($bytes / 1024, 2).'KB'; }
else if ($bytes < 1073741824){ return round($bytes / 1048576, 2).'MB'; }
else if ($bytes < 1099511627776){ return round($bytes / 1073741824, 2).'GB'; }
else{ return round($bytes / 1099511627776, 2).'TB'; }
}
function kb2bytes($kb){
return round($kb * 1024, 2);
}
function calculate_percentage($used, $total){
return @round(100 - $used / $total * 100, 2);
通知您在
$harddrive[2]
2不是有效的索引。
所以试着检查:
if(isset($harddrive[2])) // do your magic with that...