-3
<div id="head">

<?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>
4

2 回答 2

0

我会glob改用:

$i = count(glob('uploads/*')) - count(glob('uploads/*', GLOB_ONLYDIR));
于 2013-08-09T06:51:24.933 回答
0

您可以fnmatch()在循环中使用该函数来匹配文件名,如下所示:

while (false !== ($file = readdir($dir))) { 
    if (fnmatch('*.zip', $file)) {
        ++$i;
    }
}

但同样的模式也被理解glob()

于 2013-08-09T06:54:15.480 回答