Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: JesseTyler on April 20, 2005, 04:22:18 PM

Title: View .txt files instead of Saving them.
Post by: JesseTyler on April 20, 2005, 04:22:18 PM
This would be REALLY helpful on a SMF forum i'm making. (Dealing with tons of txt files.)
Title: Re: View .txt files instead of Saving them.
Post by: [Unknown] on April 20, 2005, 09:56:01 PM
Why can't you just click "open" instead of "save"?

I can tell you what to change, though.

-[Unknown]
Title: Re: View .txt files instead of Saving them.
Post by: 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
Title: Re: View .txt files instead of Saving them.
Post by: Benta on April 22, 2005, 07:52:44 PM
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?
Title: Re: View .txt files instead of Saving them.
Post by: [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.  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]
Title: Re: View .txt files instead of Saving them.
Post by: Elijah Bliss on April 22, 2005, 09:13:48 PM
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.
Title: Re: View .txt files instead of Saving them.
Post by: [Unknown] on April 22, 2005, 09:39:01 PM
So use a better browser :P.

-[Unknown]
Title: Re: View .txt files instead of Saving them.
Post by: Elijah Bliss on April 22, 2005, 09:49:03 PM
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.
Title: Re: View .txt files instead of Saving them.
Post by: JesseTyler on April 23, 2005, 10:38:36 PM
Thanks Unknown. It works perfectly now. :D