php glob() 不返回所有文件

发布于 2024-09-16 16:20:03 字数 481 浏览 3 评论 0原文

我搜索了这个网站,发现了一段非常有用的代码片段,我已经能够使用了。

  $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++;
    }

但由于某种原因,这只会返回我目录中的前 30 张图像。 (有 81 个)有人能想到为什么会发生这种情况吗?

谢谢。

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. (there are 81) Can anyone think why this is happening?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山人契 2024-09-23 16:20:03

正如我上面所说

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

就足够了。或者,如果您顽固地只想要 jpg,

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

正如手册所建议的那样

As I have said above

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

would be enough. or, if you stubbornly wants only jpg only,

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

as manual suggests

苏大泽ㄣ 2024-09-23 16:20:03

感谢大家的意见。

答案是 - 在 glob() 中使用时,文件扩展名是区分大小写的(我不知道这一点)。

我的 30 个文件以 .jpg 结尾,而其余文件已通过大小调整程序自动重命名为 .JPG

所以这意味着 glob("imagesPath/*.jpg") 仅返回小写匹配项。

另一个教训:)

希望这个答案也可以帮助其他人。 :)

Thanks to everyone for input.

Here's the answer - file extensions are CASE-SENSITIVE when used in glob() (something I was un-aware of)

30 of my files end in .jpg whilst the remaining files have been auto renamed through a resizing program to .JPG

So this means glob("imagesPath/*.jpg") only returned the lower-case matches.

Another lesson learnt :)

Hopefully this answer can help someone else too. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文