如下的代码,如何改成按文件名排序
程序员文章站
2022-05-09 12:36:56
...
php 如下的代码,如何改成按文件名排序。下面的页面 list.php是可以列出c:\filelist里的文件,可以需要用文件名来排序,另外,想多加一个动作叫Open,是在浏览器打开文件,不是下载。谢谢!
error_reporting(0);
$basedir = "c:/filelist";
if(!is_dir($basedir)) $basedir = dirname(__FILE__);
$file_name = $_GET['downfile'];
if(!empty($file_name)){
$file_dir = $basedir . "/" . $file_name;
if(dirname(realpath($file_dir))
echo "Permission Denied!";
exit;
}
if (!file_exists($file_dir)) {
echo "File Not Found!";
exit;
} else {
$file = fopen($file_dir,"r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($file_dir));
Header("Content-Disposition: attachment; filename=" . $file_name);
echo fread($file,filesize($file_dir));
fclose($file);
exit;
}
}
header("Content-type: text/html; charset=utf-8");
$requestDir = $_GET['dir'];
if(empty($requestDir)){
$dir = $basedir;
}else{
$dir = $basedir . "/" . $requestDir;
}
$dir = realpath($dir);
if($dir ?>
File Listing
error_reporting(0);
$basedir = "c:/filelist";
if(!is_dir($basedir)) $basedir = dirname(__FILE__);
$file_name = $_GET['downfile'];
if(!empty($file_name)){
$file_dir = $basedir . "/" . $file_name;
if(dirname(realpath($file_dir))
echo "Permission Denied!";
exit;
}
if (!file_exists($file_dir)) {
echo "File Not Found!";
exit;
} else {
$file = fopen($file_dir,"r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($file_dir));
Header("Content-Disposition: attachment; filename=" . $file_name);
echo fread($file,filesize($file_dir));
fclose($file);
exit;
}
}
header("Content-type: text/html; charset=utf-8");
$requestDir = $_GET['dir'];
if(empty($requestDir)){
$dir = $basedir;
}else{
$dir = $basedir . "/" . $requestDir;
}
$dir = realpath($dir);
if($dir ?>
File Listing |
Sign Out |
$predir = realpath($dir . "/../"); if($predir > $basedir) $predir = str_replace($basedir . "/","",$predir); if($predir == $basedir) $predir = "."; if($dir > $basedir) echo "Up Level"; ?> |
Folder | \n";
$basedir ? str_replace($basedir . "/",'',$dir . "/") : '') . urlencode($file)."\">$file | \n";
Filename | Date | Size | Action |
$file | \n";$lastsave | \n";$size KB | \n";$basedir ? str_replace($basedir . "/",'',$dir . "/") : '').urlencode($file)."\">Download | \n";
回复讨论(解决方案)
不用目录函数,改用 glob 函数。结果就是排序的
当然你也可以附加 GLOB_NOSORT 参数阻止这一行为
请问该改哪里? 如何改呢? 谢谢!
推荐阅读