如何在php中显示拇指文件夹图像
我有一个文件夹名称相册 并在相册中每个文件夹都有照片&拇指文件夹照片
例如
我的代码只显示这些照片
我想只显示拇指照片
我该怎么办? 请帮我解决这个问题 提前谢谢
这是代码
<?php
//path to directory to scan. i have included a wildcard for a subdirectory
$directory = "albums/*/";
//get all image files with a .jpg extension.
$images = glob("" . $directory . "*.jpg");
array_multisort(array_map('filemtime', $images), SORT_DESC, $images);
?>
<?php $num_of_files = 0; $i=0; foreach ($images as $image):?>
<div class="item"><a href="<?php echo basename(pathinfo($image, PATHINFO_DIRNAME)); ?>.html" target="_blank">
<img class="lazyOwl" src="<?php echo $image ?>" />
<p><?php echo basename(pathinfo($image, PATHINFO_DIRNAME)); ?></p>
</div>
<?php if (++$num_of_files == 3)break; ?>
<?php if(++$i%3==0): ?>
<?php endif ?>
<?php endforeach ?>
答案 0 :(得分:0)
调整目录路径:
$directory = "albums/*/thumb/";
//get all image files with a .jpg extension.
$images = glob($directory . "*.jpg");
...或尝试使用SPL
工具:
$directory = new RecursiveDirectoryIterator('albums/*/'); // or ('albums/*')
$iterator = new RecursiveIteratorIterator($directory);
$images = new RegexIterator($iterator, '/thumb\/\(.jpe?g|.png)$/i', RecursiveRegexIterator::GET_MATCH);
$images = iterator_to_array($images);
...
// iterating over $images