donglu8549 2018-10-03 08:34
浏览 36

如何显示上传到子目录中的最新图像?

I wanted to upload recent images (Basically Scrteenshot) uploaded in the sub directory. The images are in this format "Screenshot from 2018-10-03 13-10-45.png" . I am using this post as a reference. But if you see my result , what i am getting is the basically the images are ordering itself in descending order. I am new to php. I am unable to tweak the code. Basically I want the images in ascending order.

This is my code.This one is giving the descending order. I wanted to show them in ascending order. *

$images = glob('*.{gif,png,jpg,jpeg}', GLOB_BRACE); //formats to look for

$num_of_files = 4; //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."'"."><br><br>" ; //display images
     else
       break;
}

?>*

  • 写回答

1条回答 默认 最新

  • douluan4644 2018-10-03 08:40
    关注

    Just try to reverse your result array:

    array_reverse ( $result );
    

    Then you should get an ascending order.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?