我正在做一个稍微新的项目。我想知道某个目录中有多少个文件。
<div id="header">
<?php
$dir = opendir('uploads/'); # This is the directory it will count from
$i = 0; # Integer starts at 0 before counting
# While false is not equal to the filedirectory
while (false !== ($file = readdir($dir))) {
if (!in_array($file, array('.', '..') and !is_dir($file)) $i++;
}
echo "There were $i files"; # Prints out how many were in the directory
?>
</div>
这就是我到目前为止(通过搜索)得到的信息。但是,它没有正确地出现吗?我已经添加了一些注释,所以请随意删除它们,它们只是为了让我能尽可能地理解它。
如果您需要更多信息,或者觉得我对此描述得还不够充分,请随时说明。
https://stackoverflow.com/questions/12801370
复制相似问题