使用'glob'从目录中获取所有图像 [英] using 'glob' to get all images from a directory
问题描述
我正在尝试从目录中获取所有图像并进行打印。我知道我的URL是正确的,因为我正在回应$ dirname以及我保存在目录中的.jpg图像。我做错了什么?
I'm trying to get all images from a directory and print them. I know my URL is correct because I am echoing the the $dirname along with a .jpg image I have saved in the directory. What am I doing wrong?
<?php
$dirname = "uploads/{$site_country}_{$site_state}_{$site_name}/{$record_id}/";
$images = glob($dirname . "*.jpg");
foreach($images as $image) {
echo '<img src="'.$image.'"/>';
}
//check to see if $dirname is correct
echo '<img src="' . $dirname . "IMG_0002.JPG" . '"/>';
?>
//编辑
我已经解决我的问题,通过删除jpg扩展,只是拉*的文件夹中的所有内容。虽然它现在适用于我,但它不是最佳实践。它必须与不同的.jpg文件格式有关?
I have solved my problem, by removing the jpg extention and just pulling "*" for everything in the folder. Although it works for me now, its not best practice. It must be something to do with different .jpg file formats?
推荐答案
这里使用小写文件扩展名。
You used lowercase file extension here.
$images = glob($dirname . "*.jpg");
您测试输出中的大写JPG。
And uppercase JPG in your test output.
echo '<img src="' . $dirname . "IMG_0002.JPG" . '"/>';
如果您使用的是linux系统,则文件扩展名区分大小写。
If you're using a linux system then file extensions are case sensitive.
这篇关于使用'glob'从目录中获取所有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!