954,598 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Output to text (notepad) file

Hi,

I'm trying to write an html page that ends up being a text file to be opened in notepad. What content type do I use so that when you click on the link the output gets put into a text file and the user is prompted to open/save?

Do you have a sample?

Thanks,
winbatch

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

The MIME-type should be text/plain. However, you should also give your file the .txt file extension, because IE ignores MIME-types, using instead the OS' file associations.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 
The MIME-type should be text/plain. However, you should also give your file the .txt file extension, because IE ignores MIME-types, using instead the OS' file associations.



Can you give me a sample of how to set it? Basically the page is simply displaying the words (and then the text):

Content-Type: text/plain

but the browser is not acting on it and serving it up for me to download..

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

What server-side language are you using to create the file? Here's a PHP example:

<?
header("Content-type: text/plain");
?>


You can provide a meta-tag, however, it may not work in all browsers. The proper way is to set the MIME-type in the HTTP headers (which is what PHP is doing, above), rather than in the HTML document itself. The meta-tag:

<META HTTP-EQUIV="Content-Type" CONTENT="text/plain">


That would go in the "head" section of your HTML.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

perl (but only because that's what the pages written by somebody else are written in...)

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 
print "Content-Type: text/plain; charset=utf-8\n\n";


Put this before any page content.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You