View .txt files instead of Saving them.

Started by JesseTyler, April 20, 2005, 04:22:18 PM

Previous topic - Next topic

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

Right-clicking doesn't work?

[Unknown]

Alright, find this in Display.php:

header('Content-Disposition: attachment; filename="' . $real_filename . '"');
header('Content-Type: application/octet-stream');


Replace with:

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');


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]

Elijah Bliss

Quote from: [Unknown] on April 22, 2005, 08:06:12 PM
Alright, find this in Display.php:

header('Content-Disposition: attachment; filename="' . $real_filename . '"');
header('Content-Type: application/octet-stream');


Replace with:

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');


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.
-[Unknown]

Not in Safari.

[Unknown]


Elijah Bliss

Quote from: [Unknown] on April 22, 2005, 09:39:01 PM
So use a better browser :P.

-[Unknown]

Hey, Safari rules! lol. You never read a complaint from me about poor rendering in Safari, actually, that's a big reason why I like SMF, it looks really good Safari.

JesseTyler


Advertisement: