Generate dynamic text file for download

Is it possible to generate a text file using text from a database and then make that file available for download? I have a client that wants to display their info. on a web site, as well as provide it in printable and downloadable forms.

Thanks in advance for any advice!

you could always just create the file to a temporary directory and after so much time, just delete it (with php)

Originally posted by compwizard
you could always just create the file to a temporary directory and after so much time, just delete it (with php)

How would I go about creating the file? I think that’s my major hurdle.

i suggest that you read a tutorial about file manipulation in php: here are some to get you off on your feet:

You could have the text file itself be a PHP script by simply setting up your server to parse .txt files for php.

You don’t have to do any of this. You can have PHP generate just about any type of content, and deliver it in any way a browser knows how. For example:


<? //Generate text file on the fly
 
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=savethis.txt");
 
// do your Db stuff here to get the content into $content
print "This is some text...\
";
print $content;
?> 

Save that php script as text.php then in your html file,
<a href=“text.php”>Save this</a> - clicking on that link would cuase the save as dialog to pop up…

I’m a little alte to this question, but hopefully it’ll help someone in the future.

–Viral