PHP | DirectoryIterator getSize()函数
DirectoryIterator::getSize()函数是PHP中的一个内置函数,用于返回当前 DirectoryIterator 项的大小。
句法:
int DirectoryIterator::getSize( void )
参数:此函数不接受任何参数。
返回值:此函数返回文件的大小,以字节为单位。
下面的程序说明了PHP中的 DirectoryIterator::getSize()函数:
方案一:
valid()) {
// Check it is directory or not
if ($directory->isDir()) {
$file = $directory->current();
echo $file->getFilename() . " | Size: "
. $directory->getSize() . "
";
}
// Move to next element of directory
$directory->next();
}
?>
输出:
. | Size: 4096
.. | Size: 12288
dashboard | Size: 4096
img | Size: 0
webalizer | Size: 0
xampp | Size: 0
方案二:
current();
echo $dir->key() . " => " .
$file->getFilename() . " | Size: " .
$dir->getSize() . "
";
}
?>
输出:
0 => . | Size: 4096
1 => .. | Size: 12288
2 => applications.html | Size: 3607
3 => bitnami.css | Size: 177
4 => dashboard | Size: 4096
5 => favicon.ico | Size: 30894
6 => geeks.PNG | Size: 22358
7 => gfg.php | Size: 273
8 => img | Size: 0
9 => index.php | Size: 260
10 => webalizer | Size: 0
11 => xampp | Size: 0
注意:此函数的输出取决于服务器文件夹的内容。
参考: https://www. PHP.net/manual/en/directoryiterator.getsize。 PHP