php newb! php按修改/创建日期排序图像

时间:2015-08-27 14:09:27

标签: php

我是php的新手,从来没有这样做过,但有人写了一个画廊页面,它有shuffle(我猜它的排序),但我想按修改日期排序。

我试图通过这个网站上的脚本对其进行修改,但遗憾的是我搞砸了这个页面。

任何人都可以帮忙解决这个问题: -

<ul>
<?php
    $dirname = "images/";
    $images = scandir($dirname);
    usort($images, 
    create_function('$a,$b','return filetime($a) - filetime($b);')
    );
    $ignore = array(".", "..");
    foreach($images as $curimg){
        if(!in_array($curimg, $ignore)) {
            echo "<li><a href=\"$dirname$curimg\"><img src='img.php?src=$dirname$curimg&w=300&zc=1' alt='' /></a></li>\n ";
        }
    }               
?>
</ul>

我收到错误

  

致命错误:在/websites/index.php(25)中调用未定义的函数filetime():第1行的运行时创建的函数

提前致谢

1 个答案:

答案 0 :(得分:0)

usort($images,function($a,$b){
            if($a == $b){
                return 0;
            }
            return $a > $b ? 1 : -1;
});

你必须确定图像目录中的dir文件

相关问题