<?php
$dir = "/source_directory_name/";
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
我在循环后使用了sort($file);
命令,但没有结果。
答案 0 :(得分:1)
试试这个::)
$files = array();
$dir = opendir($dir);
while(false != ($file = readdir($dir))) {
if(($file != ".") and ($file != "..") and ($file != "index.php")) {
$files[] = $file; // put in array.
}
}
natsort($files); // sort.
foreach($files as $file) {
echo("<a href='$file'>$file</a> <br />\n");
}