]> git.bochard.net Git - mysite.git/commitdiff
fix path title in /files
authorbochard <mail@tenkyuu.dev>
Sun, 27 Apr 2025 14:24:28 +0000 (22:24 +0800)
committerbochard <mail@tenkyuu.dev>
Sun, 27 Apr 2025 14:24:28 +0000 (22:24 +0800)
files/bg_music/another_folder/index.php
files/bg_music/index.php
files/index.php
files/wallpapers/index.php [new file with mode: 0644]

index c102ebcac33b505a7298e8d6e52d0711589b15fc..1067e456922a73270de7f926ba812b959da310cf 100644 (file)
@@ -1,35 +1,17 @@
 <?php
-// Set the current directory
-$dir = ".";
+$urlPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+$urlPath = rtrim($urlPath, "/");
+$fullPath = $urlPath === "" ? "/" : $urlPath;
 
-// Get the full path for the current directory
-$currentPath = realpath($dir);
-$baseDir = realpath(dirname(__FILE__)); // Get the base directory path
-$relativePath = str_replace($baseDir, '', $currentPath); // Get the relative path
-$relativePath = trim($relativePath, '/'); // Trim leading and trailing slashes
-
-// Construct the full path for the title
-if (empty($relativePath)) {
-    $fullPath = basename($baseDir); // This will be "files" when in the root
-} else {
-    $fullPath = basename($baseDir) . '/' . $relativePath; // This will be "files/bg_music" or similar
-}
-
-// If the relative path is not empty, prepend a slash
-if (!empty($relativePath)) {
-    $fullPath = basename($baseDir) . '/' . $relativePath;
-}
-
-if ($handle = opendir($dir)) {
+if ($handle = opendir(".")) {
     echo "<html>";
-    echo "<head><title>Index of /$fullPath</title></head>";
+    echo "<head><title>Index of $fullPath</title></head>";
     echo "<body>";
-    echo "<h1>Index of /$fullPath</h1><hr><pre>";
+    echo "<h1>Index of $fullPath</h1><hr><pre>";
     echo '<a href="../">../</a>' . PHP_EOL;
 
     $items = [];
     while (false !== ($entry = readdir($handle))) {
-        // Skip the current and parent directory entries and index.php
         if ($entry != "." && $entry != ".." && $entry != "index.php") {
             $items[] = $entry;
         }
@@ -39,16 +21,15 @@ if ($handle = opendir($dir)) {
     sort($items);
 
     foreach ($items as $entry) {
-        $filePath = $dir . "/" . $entry;
+        $filePath = "./" . $entry;
         $lastModified = date("d-M-Y H:i", filemtime($filePath));
         $size = is_dir($filePath) ? "-" : filesize($filePath);
         $link = htmlspecialchars($entry);
-        
-        // Check if it's a directory and add a trailing slash
+
         if (is_dir($filePath)) {
-            $link .= '/'; // Add trailing slash for directories
+            $link .= '/';
         }
-        
+
         echo "<a href=\"$entry\">$link</a>" . str_repeat(" ", 50 - strlen($link)) . "$lastModified" . str_repeat(" ", 10 - strlen($size)) . "$size" . PHP_EOL;
     }
 
@@ -58,4 +39,4 @@ if ($handle = opendir($dir)) {
 } else {
     echo "Unable to open directory.";
 }
-?>
+?>
\ No newline at end of file
index c102ebcac33b505a7298e8d6e52d0711589b15fc..1067e456922a73270de7f926ba812b959da310cf 100644 (file)
@@ -1,35 +1,17 @@
 <?php
-// Set the current directory
-$dir = ".";
+$urlPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+$urlPath = rtrim($urlPath, "/");
+$fullPath = $urlPath === "" ? "/" : $urlPath;
 
-// Get the full path for the current directory
-$currentPath = realpath($dir);
-$baseDir = realpath(dirname(__FILE__)); // Get the base directory path
-$relativePath = str_replace($baseDir, '', $currentPath); // Get the relative path
-$relativePath = trim($relativePath, '/'); // Trim leading and trailing slashes
-
-// Construct the full path for the title
-if (empty($relativePath)) {
-    $fullPath = basename($baseDir); // This will be "files" when in the root
-} else {
-    $fullPath = basename($baseDir) . '/' . $relativePath; // This will be "files/bg_music" or similar
-}
-
-// If the relative path is not empty, prepend a slash
-if (!empty($relativePath)) {
-    $fullPath = basename($baseDir) . '/' . $relativePath;
-}
-
-if ($handle = opendir($dir)) {
+if ($handle = opendir(".")) {
     echo "<html>";
-    echo "<head><title>Index of /$fullPath</title></head>";
+    echo "<head><title>Index of $fullPath</title></head>";
     echo "<body>";
-    echo "<h1>Index of /$fullPath</h1><hr><pre>";
+    echo "<h1>Index of $fullPath</h1><hr><pre>";
     echo '<a href="../">../</a>' . PHP_EOL;
 
     $items = [];
     while (false !== ($entry = readdir($handle))) {
-        // Skip the current and parent directory entries and index.php
         if ($entry != "." && $entry != ".." && $entry != "index.php") {
             $items[] = $entry;
         }
@@ -39,16 +21,15 @@ if ($handle = opendir($dir)) {
     sort($items);
 
     foreach ($items as $entry) {
-        $filePath = $dir . "/" . $entry;
+        $filePath = "./" . $entry;
         $lastModified = date("d-M-Y H:i", filemtime($filePath));
         $size = is_dir($filePath) ? "-" : filesize($filePath);
         $link = htmlspecialchars($entry);
-        
-        // Check if it's a directory and add a trailing slash
+
         if (is_dir($filePath)) {
-            $link .= '/'; // Add trailing slash for directories
+            $link .= '/';
         }
-        
+
         echo "<a href=\"$entry\">$link</a>" . str_repeat(" ", 50 - strlen($link)) . "$lastModified" . str_repeat(" ", 10 - strlen($size)) . "$size" . PHP_EOL;
     }
 
@@ -58,4 +39,4 @@ if ($handle = opendir($dir)) {
 } else {
     echo "Unable to open directory.";
 }
-?>
+?>
\ No newline at end of file
index c102ebcac33b505a7298e8d6e52d0711589b15fc..1067e456922a73270de7f926ba812b959da310cf 100755 (executable)
@@ -1,35 +1,17 @@
 <?php
-// Set the current directory
-$dir = ".";
+$urlPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+$urlPath = rtrim($urlPath, "/");
+$fullPath = $urlPath === "" ? "/" : $urlPath;
 
-// Get the full path for the current directory
-$currentPath = realpath($dir);
-$baseDir = realpath(dirname(__FILE__)); // Get the base directory path
-$relativePath = str_replace($baseDir, '', $currentPath); // Get the relative path
-$relativePath = trim($relativePath, '/'); // Trim leading and trailing slashes
-
-// Construct the full path for the title
-if (empty($relativePath)) {
-    $fullPath = basename($baseDir); // This will be "files" when in the root
-} else {
-    $fullPath = basename($baseDir) . '/' . $relativePath; // This will be "files/bg_music" or similar
-}
-
-// If the relative path is not empty, prepend a slash
-if (!empty($relativePath)) {
-    $fullPath = basename($baseDir) . '/' . $relativePath;
-}
-
-if ($handle = opendir($dir)) {
+if ($handle = opendir(".")) {
     echo "<html>";
-    echo "<head><title>Index of /$fullPath</title></head>";
+    echo "<head><title>Index of $fullPath</title></head>";
     echo "<body>";
-    echo "<h1>Index of /$fullPath</h1><hr><pre>";
+    echo "<h1>Index of $fullPath</h1><hr><pre>";
     echo '<a href="../">../</a>' . PHP_EOL;
 
     $items = [];
     while (false !== ($entry = readdir($handle))) {
-        // Skip the current and parent directory entries and index.php
         if ($entry != "." && $entry != ".." && $entry != "index.php") {
             $items[] = $entry;
         }
@@ -39,16 +21,15 @@ if ($handle = opendir($dir)) {
     sort($items);
 
     foreach ($items as $entry) {
-        $filePath = $dir . "/" . $entry;
+        $filePath = "./" . $entry;
         $lastModified = date("d-M-Y H:i", filemtime($filePath));
         $size = is_dir($filePath) ? "-" : filesize($filePath);
         $link = htmlspecialchars($entry);
-        
-        // Check if it's a directory and add a trailing slash
+
         if (is_dir($filePath)) {
-            $link .= '/'; // Add trailing slash for directories
+            $link .= '/';
         }
-        
+
         echo "<a href=\"$entry\">$link</a>" . str_repeat(" ", 50 - strlen($link)) . "$lastModified" . str_repeat(" ", 10 - strlen($size)) . "$size" . PHP_EOL;
     }
 
@@ -58,4 +39,4 @@ if ($handle = opendir($dir)) {
 } else {
     echo "Unable to open directory.";
 }
-?>
+?>
\ No newline at end of file
diff --git a/files/wallpapers/index.php b/files/wallpapers/index.php
new file mode 100644 (file)
index 0000000..1067e45
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+$urlPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+$urlPath = rtrim($urlPath, "/");
+$fullPath = $urlPath === "" ? "/" : $urlPath;
+
+if ($handle = opendir(".")) {
+    echo "<html>";
+    echo "<head><title>Index of $fullPath</title></head>";
+    echo "<body>";
+    echo "<h1>Index of $fullPath</h1><hr><pre>";
+    echo '<a href="../">../</a>' . PHP_EOL;
+
+    $items = [];
+    while (false !== ($entry = readdir($handle))) {
+        if ($entry != "." && $entry != ".." && $entry != "index.php") {
+            $items[] = $entry;
+        }
+    }
+    closedir($handle);
+
+    sort($items);
+
+    foreach ($items as $entry) {
+        $filePath = "./" . $entry;
+        $lastModified = date("d-M-Y H:i", filemtime($filePath));
+        $size = is_dir($filePath) ? "-" : filesize($filePath);
+        $link = htmlspecialchars($entry);
+
+        if (is_dir($filePath)) {
+            $link .= '/';
+        }
+
+        echo "<a href=\"$entry\">$link</a>" . str_repeat(" ", 50 - strlen($link)) . "$lastModified" . str_repeat(" ", 10 - strlen($size)) . "$size" . PHP_EOL;
+    }
+
+    echo "</pre><hr>";
+    echo "</body>";
+    echo "</html>";
+} else {
+    echo "Unable to open directory.";
+}
+?>
\ No newline at end of file