From adf43512f5ba211150ca455144df26169b025d9b Mon Sep 17 00:00:00 2001
From: imcraftsman
Date: Wed, 22 Jan 2025 18:15:51 +0800
Subject: [PATCH] Update tinyfilemanager.php
when we login as an ordinary client, our folders which assigned by the administrator are usually not in the webserver root directory. so, we could not get the file's hyperlink, and we could not preview our pictures and watch our video online.
now, the problem is solved. I add a proxy to settle this.
modified list:
1) add a proxy;
2) modify image's/video's hyperlinks
3) modify file's 'direct link' related with open button.
in addition:
There is a clerical error in lin "$fileTypes['jfif'] = 'image/jpg';" it should be "$fileTypes['jfif'] = 'image/jfif';"
in my another PR(PR id= #1269)
---
tinyfilemanager.php | 118 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 110 insertions(+), 8 deletions(-)
diff --git a/tinyfilemanager.php b/tinyfilemanager.php
index a8c0f08..fbffb4c 100644
--- a/tinyfilemanager.php
+++ b/tinyfilemanager.php
@@ -458,6 +458,79 @@ unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style
/*************************** ACTIONS ***************************/
+// file proxy
+if (isset($_GET['proxy_file'])) {
+ header('Access-Control-Allow-Origin: *');
+ header('Access-Control-Allow-Methods: GET');
+
+ function sanitizePath($path) {
+ if (substr($path, 0, 1) !== '/') {
+ die('Invalid file path.');
+ }
+ if ($path === '/')
+ return '/';
+ return realpath($path);
+ }
+
+ // get file path
+ $filePath = isset($_GET['path'])?$_GET['path']:"/";
+
+ $filePath = sanitizePath($filePath);
+
+ if ($filePath === false || !file_exists($filePath)) {
+ http_response_code(404);
+ die('File not found or inaccessible.');
+ }
+
+ if (is_dir($filePath)) {
+ // if it is dir,list the content
+ $fileList = getFileList($filePath);
+ echo generateDirectoryListing($filePath, $fileList);
+ exit;
+ } else {
+ // if it is image or vedio file ,return the immage file content
+ if (!is_readable($filePath)) {
+ http_response_code(403);
+ die("File is not readable.");
+ }
+ $mimeType = mime_content_type($filePath);
+ header('Content-Type: ' . $mimeType);
+ header('Content-Length: ' . filesize($filePath));
+ readfile($filePath);
+ exit;
+ }
+}
+
+// get file lists
+function getFileList($dir)
+{
+ $files = array();
+ $entries = scandir($dir);
+ foreach ($entries as $entry) {
+ if ($entry != "." && $entry != "..") {
+ $files[] = $entry;
+ }
+ }
+ return $files;
+}
+// create file lists HTML
+function generateDirectoryListing($dir, $fileList)
+{
+ $html = "Index of {$dir}";
+ $html .= "