超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<dirnamedisk_total_space>
Last updated: Fri, 22 Jun 2007

disk_free_space

(PHP 4 >= 4.1.0, PHP 5)

disk_free_space -- 返回目录中的可用空间

说明

float disk_free_space ( string directory)

给出一个包含有一个目录的字符串,本函数将根据相应的文件系统或磁盘分区返回可用的字节数。

例子 1. disk_free_space() 例子

<?php
// $df 包含根目录下可用的字节数
$df = disk_free_space("/");
?>

注: 本函数不能作用于远程文件,被检查的文件必须通过服务器的文件系统访问。

参见 disk_total_space()




add a note add a note User Contributed Notes
disk_free_space
nospam at jusunlee dot com
30-Jul-2003 11:45
The above is only useful if you need to find the total used space of a mountpoint. If you are looking for a script that determines the total used space of a directory and all of its contents (including subdirectories), heres a recursive function that should do the work.

<?
$total = 0;
function spaceUsed($dir) {
if (is_dir($dir)) {
 if ($dh = opendir($dir)) {
  while (($file = readdir($dh)) !== false) {
   if (is_dir($dir.$file) && $file != '.' && $file != '..') {
   spaceUsed($dir.$file.'/');
   } else {
    $GLOBALS['total'] += filesize($dir.$file);
   }
  }
 closedir($dh);
 }
}
}

spaceUsed('/path/to/directory/');

$total /= 1048576;
echo round($total, 1).' mb';
?>

<dirnamedisk_total_space>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22