Page 1 of 1

Modify Text File Download Without Modifying Saved File?

Posted: Wed Sep 30, 2009 8:23 am
by wft
Hi. I'm new to the forum. I have a rather unusual need, and I'm seeking ideas on how to fulfill it.

I want to write a PHP script that will take an existing text file and offer it as a downloadable link on a web page. Simple enough, except that when the user clicks the link to download it, I want the file to automatically get modified on the fly before delivering it to the user. but without any changes being made to the original file stored on the server. In other words, I want to do something similar to what can be done with an image, like adding text to the image (or some other modification) before delivering it to the user; instead of modifying an image, I want to modify a .txt file (or .mobi, or .pdf, or .rtf, etc.)

Any ideas?

Re: Modify Text File Download Without Modifying Saved File?

Posted: Wed Sep 30, 2009 9:45 am
by jackpf
Umm....read the file, make the changes, and then send it to the user? What are you having trouble with? :/

Re: Modify Text File Download Without Modifying Saved File?

Posted: Wed Sep 30, 2009 11:04 am
by wft
jackpf wrote:Umm....read the file, make the changes, and then send it to the user? What are you having trouble with? :/
Forgive me if I'm overlooking something obvious. My understanding (probably wrong) is that you normally have to write the changes to the stored file before allowing the user to download it. I'm not used to handling "in stream" changes, which is why I'm asking for help.

Re: Modify Text File Download Without Modifying Saved File?

Posted: Wed Sep 30, 2009 12:53 pm
by jackpf
Well, to download a file, you send all the headers...and then send the file contents right?

So, make a script, which sends all the headers, loads up the file, makes whatever changes it wants, and then sends the file.

Have a look at fopen() or file_get_contents() or something similar.

Re: Modify Text File Download Without Modifying Saved File?

Posted: Thu Oct 01, 2009 6:06 am
by wft
Yes, of course. Thanks for your help.