PHP脚本,显示文件夹中的图像 [英] PHP script that shows the images in a folder
本文介绍了PHP脚本,显示文件夹中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个显示文件夹中图像的脚本.但是,有什么办法可以让我首先显示最新的图像?而不是相反.
This is a script that shows images in a folder. But is there a way that I can show the latest image first? Instead of the other way around.
$images = glob('*.{gif,png,jpg,jpeg}', GLOB_BRACE); // formats to look for
$num_of_files = 2; // number of images to display
foreach($images as $image)
{
$num_of_files--;
if($num_of_files > -1) // this made me laugh when I wrote it
echo "<b>".$image."</b><br>Created on ".date('D, d M y H:i:s', filemtime($image)) ."<br><img src="."'".$image."' style='width: 95%'"."><br><br>" ; // display images
else
break;
}
推荐答案
您需要将图像放入数组中,然后按上次修改的顺序进行排序.
You need to put your images into an array and then sort by last modified.
类似这样的东西:
$imagesToSort = glob('*.{gif,png,jpg,jpeg}');
usort($imagesToSort, function($a, $b) {
return filemtime($a) < filemtime($b);
});
这篇关于PHP脚本,显示文件夹中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文