prasathmani / tinyfilemanager

Single-file PHP file manager, browser and manage your files efficiently and easily with tinyfilemanager
https://tinyfilemanager.github.io
GNU General Public License v3.0
4.62k stars 1.63k forks source link

Impossible to edit an empty file with certain file extensions #986

Open ungive opened 1 year ago

ungive commented 1 year ago

I have tested this with the docker image tagged "master" (from Feb 26 2023), logged in as the default admin user (command used: sudo docker run -d -v /media/jonas/renkforce/USERDATA/Minecraft/tinyfilemanager/:/var/www/html/data -p 80:80 --restart=always --name tinyfilemanager tinyfilemanager/tinyfilemanager:master)

I created a new file via the "New Item" button in the header with the name "test.mcfunction". Upon clicking on this file I noticed there is no "Edit" or "Advanced Editor" button. This button exists with other plaintext files (e.g. txt).

Attempting to edit it by using the edit URL for this file yields an empty page with no options to edit the file (http://localhost/index.php?p=data&edit=test.mcfunction).

How can I edit this file through tinyfilemanager, without downloading and uploading it again?

I think all files that aren't definitely binary files should be editable, even if their file extension is unknown.

prasathmani commented 1 year ago

add your file extension to https://github.com/prasathmani/tinyfilemanager/blob/master/tinyfilemanager.php#L2972

ungive commented 1 year ago

Thanks for the response! I already did that as a temporary workaround, but personally, I would suggest to go for a more permanent solution, where the choice of files that get to be edited is less restrictive and more permissive.

Known binary file MIME types (like "application/octet-stream", "video/x-matroska", ...) should be disallowed for text editing, but anything that is plain text ("text/plain" or "application/x-empty" for empty files) should be editable. The PHP mime_content_type function tries to guess the MIME type just from the content, without hard-coding file extensions.

nerun commented 1 month ago

I do agree. Tested PR #988 and it works fine with 2.5.3 (but tested with copy/paste the changes).