以下脚本有效:
$dir = "images/";
$images = glob($dir."*.jpg" );
foreach( $images as $image ):
echo"<li><img src='". '/' . $image . "' /></li>";
endforeach;
问题出现在下面的PHP脚本中。不包括更多存在图片的目录
$dir = "images/images2/";
$images = glob($dir."*.jpg" );
foreach( $images as $image ):
echo"<li><img src='". '/' . $image . "' /></li>";
endforeach;
如何解决此问题。
答案 0 :(得分:1)
您也应该在使用图像时添加子路径:
$subpath = "images2/";
$dir = "images/" . $subpath;
......
echo ".....<img src='/" . $subpath . $image . "' />....";
答案 1 :(得分:1)
尝试在
中提供完整路径$dir = "images/images2/";
答案 2 :(得分:0)
尝试将RecursiveIteratorIterator与RecursiveDirectoryIterator
结合使用$path = realpath('/path/you/want/to/search/in');
$objects = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
if($object->getFilename() === '*.jpg') {
echo $object->getPathname();
}
}
补充阅读: