我把图像存储在一个目录结构中,有点像这样:
- 图像
- foo
- 拇指
- awefawef.jpg
- dtyhty.jpg
- 已满
- awefawef.jpg
- dtyhty.jpg
- eriguherg.jpg
- 拇指
- 酒吧
- 拇指
- erg.jpg
- 已满
- erg.jpg
- tyjhr5g.jpg
- 拇指
- some_other_dir
- 等等
- foo
(注意:"拇指"目录中的图像数量不会总是与相邻的"完整"目录中相同。)
所以:我需要使用PHP来计算所有"完整"目录中的图像总数
我相信我可以找到一种方法来做到这一点,方法是获得"图像"的所有子目录的列表,然后在它们之间循环,并计算每个"完整"文件夹中的图像。但是,由于将有数千个目录,每个文件夹中有数百个图像,我正在寻找最有效的解决方案——这需要网站经常完成。
这里最有效的方法是什么?
这将适用于您概述的情况:
$imagecount = count(glob("images/*/full/*.jpg"));
$count = count(glob("images/*.jpg"));
echo "In images have $count images";
试试这个:-
<?php
$directory='images';
$count=0;
$full_images='';
if($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if(is_dir($directory.'/'.$file))
{
if($handle1 = opendir($directory.'/'.$file."/full")) {
while (false !== ($file1 = readdir($handle1))) {
if(!is_dir($file1))
{
$count=$count+1;
$full_images[$file]['full'][]=$file1;
}
}
}
}
}
closedir($handle);
}
echo "Total count images in all of the full directories in: <b>".$count."</b> <br />";
foreach($full_images as $k => $v)
{
foreach($v as $key)
{
echo "Total count images in ".$k."''s full directory in: <b>".count($key)."</b><br />";
}
}
?>