简体   繁体   English

php glob()没有返回所有文件

[英]php glob() not returning all files

I searched this site and found a very useful snippet of code that i've been able to use. 我搜索了这个网站,发现了一个非常有用的代码片段,我已经能够使用了。

  $counter = 0; 
     foreach (glob("images/gallery/photo_gallery/resized/*.jpg") as $pathToThumb)
    {
        $filename = basename($pathToThumb);
        $pathToLarge = 'images/gallery/photo_gallery/' . $filename;
        echo ('<a href="'.$pathToLarge.'"><img src="'.$pathToThumb.'" /></a>');
        $counter++;
    }

But for some reason this will only return the first 30 images in my directory. 但由于某种原因,这只会返回我目录中的前30个图像。 (there are 81) Can anyone think why this is happening? (有81个)有谁能想到为什么会这样?

Thanks. 谢谢。

Thanks to everyone for input. 感谢大家的投入。

Here's the answer - file extensions are CASE-SENSITIVE when used in glob() (something I was un-aware of) 这是答案 - 在glob()中使用时,文件扩展名为CASE-SENSITIVE(我不知道的事情)

30 of my files end in .jpg whilst the remaining files have been auto renamed through a resizing program to .JPG 我的30个文件以.jpg结尾,而其余文件已通过调整大小程序自动重命名为.JPG

So this means glob("imagesPath/*.jpg") only returned the lower-case matches. 所以这意味着glob("imagesPath/*.jpg")只返回小写匹配。

Another lesson learnt :) 另一个经验教训:)

Hopefully this answer can help someone else too. 希望这个答案也可以帮助其他人。 :) :)

As I have said above 正如我上面所说的那样

$path = 'images/gallery/photo_gallery/resized/*';

would be enough. 就足够了。 or, if you stubbornly wants only jpg only, 或者,如果你固执地只想要jpg,

$path = 'images/gallery/photo_gallery/resized/*.[Jj][Pg][Gg]';

as manual suggests 如手册所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM