PHP:检索并显示(以HTML格式)文件夹中的最新图像文件

时间:2017-07-18 00:14:15

标签: html scandir

我想扫描文件夹,按修改时间对该文件夹中的文件进行排序,并显示最新文件。这是我到目前为止所做的:

<?php

function scanDir ($dir){

    $fileTimeArray = array();

    // Scan directory and get each file date
    foreach (scandir($dir) as $fileTime){
        $fileTimeArray[$fileTime] = filemtime($dir . '/' . $fileTime);  
    }

    //Sort file times
    $fileTimeArray = arsort($fileTimeArray);

    return($fileTimeArray[0]);
}

?>

我在另一个php文件中调用此函数,在img标记的src中。

截至目前

<img src=Array>

我在功能中哪里出错了?谢谢!!!

0 个答案:

没有答案