3

我搜索了这个站点,发现了一个非常有用的代码片段,我可以使用它。

  $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 个)谁能想到为什么会这样?

谢谢。

4

2 回答 2

1

正如我上面所说

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

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

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

正如手册建议的那样

于 2010-08-28T10:19:39.460 回答
1

感谢大家的意见。

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

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

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

另一个教训:)

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

于 2010-08-28T10:10:32.660 回答