Php
The following code, how to change the sort by file name. The following page list.php is can be listed in the C:\filelist file, you can need to sort by the file name, in addition, want to add an action called Open, is in the browser open file, not download. Thank you!
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)) < $basedir) {
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 < $basedir) $dir = $basedir;
?>
<title>File Listing</title>
$predir = Realpath ($dir. "/.. /");
if ($predir > $basedir) $predir = Str_replace ($basedir. "/", "", $predir);
if ($predir = = $basedir) $predir = ".";
if ($dir > $basedir) echo "Up level";
?>
|
$dirs = @opendir ($dir); $count = 0; while ($file = @readdir ($dirs)) {$b = "$dir/$file"; $a = @is_dir ($b); if ($a = = "1") {if ($file! = "...") && $file! = ".") {if ($count < 1) {$count + +; echo "
\ n "; echo "
Folder | \ n "; echo "
\ n "; } echo "
\ n "; echo "
$basedir? Str_replace ($basedir. "/", ", $dir. "/") : '') . UrlEncode ($file). " \ "> $file | \ n "; echo "
\ n "; }}} @closedir ($dirs); ?>
Filename |
Date |
Size |
Action |
$dirs = @opendir ($dir); while ($file = @readdir ($dirs)) {$b = "$dir/$file"; $a = @is_dir ($b); if ($a = = "0") {$size = @filesize ("$dir/$file"); $size = $size/1024; $size = @number_format ($size, 2); $lastsave = @date ("y-n-d h:i:s", Filemtime ("$dir/$file")); echo "
\ n "; echo "
$file | \ n "; echo "
$lastsave | \ n "; echo "
$size KB | \ n "; echo "
$basedir? Str_replace ($basedir. "/", ", $dir. "/"): "). UrlEncode ($file)." \ ">download | \ n "; echo "
\ n "; }} @closedir ($dirs); ?>
Reply to discussion (solution)
Use the Glob function instead of the directory function. The result is a sort of
Of course you can also attach the Glob_nosort parameter to block this behavior
Where should I change? How to change it? Thank you!