make urls more readable

This commit is contained in:
lolcat 2024-03-21 10:39:48 -04:00
parent 9c01f3f4ab
commit 3643b79b4b
1 changed files with 13 additions and 6 deletions

View File

@ -8,6 +8,13 @@ $max_results = 100; // will break; once we reach limit, -1 for no limit
$motd = "get fucked";
$script_name = "listdir.php";
function encode_path($path){
return implode("/", array_map(function($v){
return urlencode($v);
}, explode("/", $path)));
}
function do_error($code, $title, $text, $motd, $script_name){
http_response_code($code);
@ -179,7 +186,7 @@ if(isset($_GET["query"])){
break;
case "pcre":
$match = preg_match($query, $filename);
$match = @preg_match($query, $filename);
if($match === false){
@ -224,7 +231,7 @@ if(isset($_GET["query"])){
'<tr>' .
'<td>' . ($is_dir ? "&lt;DIR&gt;" : "&lt;FILE&gt;") . '</td>' .
'<td>' .
'<a href="' . $script_name . '?path=' . urlencode($fullpath) . '">' .
'<a href="' . $script_name . '?path=' . encode_path($fullpath) . '">' .
htmlspecialchars(
$filename
) .
@ -321,7 +328,7 @@ if(is_dir($realpath)){
$up = explode("/", $relative_path);
unset($up[count($up) - 1]);
$up = $script_name . "?path=" . urlencode(implode("/", $up));
$up = $script_name . "?path=" . encode_path(implode("/", $up));
}
do_header("index of " . $relative_path, "", "and", false, "", $up);
@ -342,7 +349,7 @@ if(is_dir($realpath)){
'<tr><td></td>' .
'<td>' . ($is_dir ? "&lt;DIR&gt;" : "&lt;FILE&gt;") . '</td>' .
'<td>' .
'<a href="' . $script_name . '?path=' . urlencode(rtrim($relative_path, "/") . "/" . $filename) . '">' .
'<a href="' . $script_name . '?path=' . encode_path(rtrim($relative_path, "/") . "/" . $filename) . '">' .
htmlspecialchars(
$filename
) .
@ -367,7 +374,7 @@ if(is_dir($realpath)){
echo
'<td>' .
'<a href="' . $script_name . '?path=' . urlencode($path) . '&page=' . ($page - 1) . '">&lt;PREV&gt;</a>' .
'<a href="' . $script_name . '?path=' . encode_path($path) . '&page=' . ($page - 1) . '">&lt;PREV&gt;</a>' .
'</td>';
}else{
@ -382,7 +389,7 @@ if(is_dir($realpath)){
echo
'<td>' .
'<a href="' . $script_name . '?path=' . urlencode($path) . '&page=' . ($page + 1) . '">&lt;NEXT&gt;</a>' .
'<a href="' . $script_name . '?path=' . encode_path($path) . '&page=' . ($page + 1) . '">&lt;NEXT&gt;</a>' .
'</td>';
}else{