This is what it currently says:
function posts_get($directory,$ext)
{
if (is_dir($directory)) {
$handle = opendir($directory);
while ($file = readdir($handle)){
$subdir = $directory . '/' .$file;
if ($file != '.' && $file !='..' && is_dir($subdir)){
posts_get($subdir,$ext);
} else if( $file != '.' && $file != '..') {
$fileInfo = pathinfo($subdir);
$fileExt = $fileInfo['extension'];
if ($fileExt == $ext){
echo 'File name:' . $file . '————' . 'Path:' . '//' .$_SERVER['HTTP_HOST'] . '/' .$directory . '/' . $file . ' <br />';
}}}
closedir($handle);
}
}
Get the html files in the posts directory. There are 5 files in the test directory, 404.html, 405.html, 406.html, 407.html, 408.html
The output results are as follows:
File name:405.html————Path://hotbox.ryongyon.com/posts/405.html
File name: 406.html————Path://hotbox.ryongyon.com/posts/406.html
File name: 407.html————Path://hotbox.ryongyon.com/posts/407.html
File name: 408.html————Path://hotbox.ryongyon.com/posts/408.html
File name: 404.html————Path://hotbox.ryongyon.com/posts/404.html
How to sort readdir results according to the date of file creation
filectime
Get file creation time and convert to timestampDefine an empty array and store data in the format
时间戳=>文件名
ksort
或者krsort
Sort arraydone