Customizing SMF > Tips and Tricks
View .txt files instead of Saving them.
JesseTyler:
This would be REALLY helpful on a SMF forum i'm making. (Dealing with tons of txt files.)
[Unknown]:
Why can't you just click "open" instead of "save"?
I can tell you what to change, though.
-[Unknown]
JesseTyler:
Ok look.
I'd want it to be able to just attach the .txt file to the post. Then click on it and have it open like i'm viewing a .txt file directly. :p
Benta:
--- Quote from: JesseTyler on April 21, 2005, 01:09:35 AM ---Ok look.
I'd want it to be able to just attach the .txt file to the post. Then click on it and have it open like i'm viewing a .txt file directly. :p
--- End quote ---
Right-clicking doesn't work?
[Unknown]:
Alright, find this in Display.php:
--- Code: --- header('Content-Disposition: attachment; filename="' . $real_filename . '"');
header('Content-Type: application/octet-stream');
--- End code ---
Replace with:
--- Code: --- header('Content-Disposition: ' . (substr($real_filename, -4) === '.txt' ? 'inline' : 'attachment') . '; filename="' . $real_filename . '"');
if (substr($real_filename, -4) === '.txt')
header('Content-Type: text/plain');
else
header('Content-Type: application/octet-stream');
--- End code ---
But, I still think the browser has more elegant support for this. Meaning, if I click on an attachment WITHOUT making the above change, I get a dialog that gives me the option to "Open" or "Save" the document. Choosing "Open" opens it in Notepad, which I like to use to view text files and even prefer to my web browser.
This change cannot make it automatically pick "Open" and use Notepad, and such a thing is not going to be possible from a webpage. However, it will make the web browser simply display the file instead of downloading it.
-[Unknown]
Navigation
[0] Message Index
[#] Next page
Go to full version