我需要关于disk_total_space函数的帮助..
我在我的代码中有这个
<?php
$sql="select * from users order by id";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)) {
?>
Name : <?php echo $row['name']; ?>
Email : <?php echo $row['email']; ?>
Diskspace Available : <?php
$dir = "C:/xampp/htdocs/freehosting/".$row['name'];
disk_total_space($dir);
} ?>但是,这会为每个用户返回相同的磁盘空间。
有谁能给我点启发吗?
谢谢:)
发布于 2009-01-21 17:22:48
我想你想要的东西是这样的:
function foldersize($path) {
$total_size = 0;
$files = scandir($path);
foreach($files as $t) {
if (is_dir(rtrim($path, '/') . '/' . $t)) {
if ($t<>"." && $t<>"..") {
$size = foldersize(rtrim($path, '/') . '/' . $t);
$total_size += $size;
}
} else {
$size = filesize(rtrim($path, '/') . '/' . $t);
$total_size += $size;
}
}
return $total_size;
}
function format_size($size) {
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}
$SIZE_LIMIT = 5368709120; // 5 GB
$sql="select * from users order by id";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)) {
$disk_used = foldersize("C:/xampp/htdocs/freehosting/".$row['name']);
$disk_remaining = $SIZE_LIMIT - $disk_used;
print 'Name: ' . $row['name'] . '<br>';
print 'diskspace used: ' . format_size($disk_used) . '<br>';
print 'diskspace left: ' . format_size($disk_remaining) . '<br><hr>';
}编辑:递归函数最初有一个bug。现在它还应该读取原始文件夹中的文件夹,以及这些文件夹中的文件夹,依此类推。
发布于 2009-01-21 17:17:02
http://us2.php.net/disk_total_space说,
“给定一个包含目录的字符串,此函数将返回对应的文件系统或磁盘分区上的字节总数。”
您可能会看到C:的total_space:
Alternative solutions do exist for both Windows and Linux。
发布于 2009-01-21 17:17:16
我认为该方法只会告诉您有关给定目录所在的文件系统或分区的信息。不过,您可以尝试简单地使用du:
$space_used=`du -sh $dir`;-s总结了整个目录,-h以“人”为单位返回结果,如MB和GB。
编辑:抱歉,我错过了WIndows上的这篇文章。WIll留下答案,以防有人搜索类似的问题。对于windows,
https://stackoverflow.com/questions/466140
复制相似问题