php glob() 不返回所有文件
我搜索了这个网站,发现了一段非常有用的代码片段,我已经能够使用了。
$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如我上面所说
就足够了。或者,如果您顽固地只想要 jpg,
正如手册所建议的那样
As I have said above
would be enough. or, if you stubbornly wants only jpg only,
as manual suggests
感谢大家的意见。
答案是 - 在 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. :)