开发者

print date of the folder by php

I use this code to list the directories.

$files = glob('back/1/*',GLOB_ONLYDIR);

foreach ($files as $f){
    $tmp[basename($f)] = filemtime($f);
}

arsort($tmp);
$files = array_keys($tmp);

foreach($files as $folde开发者_JS百科r){
    echo $folder;
}

But I want to print the date of the creation of the dir, how could I do that?


Basically you need to call filemtime (or filectime for creation time) whenever you print the file/directory name. You already do that to fill the $tmp array, which your sorting is based on. All you need to do now, is to print out the value of the $tmp array in your final loop where you print out the folder names.

For example like this:

foreach($files as $folder){
    $date = date( 'd.m.Y H:i', $tmp[$folder] );
    echo $folder . ' (' . $date . ')';
}

If you want to print out the creation time but still sort on the modification time, you can simply call filectime in the loop instead. Note however that you need to reconstruct the original pathname, as you used basename on the path before.

foreach($files as $folder){
    $date = date( 'd.m.Y H:i', filectime( 'back/1/' . $folder ) );
    echo $folder . ' (' . $date . ')';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜