String to downloadable file.

Hi All,

I have a string with text and want to be able to download the string as a
file.
I browsed php.net, but cant find any clou....

I do NOT want to write the string to a file what you can download
afterwards...
The file might be .txt, .rtf or something like that.

Can anyone help me with this?

Thanks in advance,
Maurice
Maurice [ Do, 05 Juli 2007 12:33 ] [ ID #1760493 ]

Re: String to downloadable file.

"Maurice van 't Loo" <maurice [at] lievergeenspam.nl> wrote in message
news:468cc8f9$0$89292$dbd4d001 [at] news.wanadoo.nl...
> Hi All,
>
> I have a string with text and want to be able to download the string as a
> file.
> I browsed php.net, but cant find any clou....
>
> I do NOT want to write the string to a file what you can download
> afterwards...
> The file might be .txt, .rtf or something like that.
>
> Can anyone help me with this?

Where does this string live?

If it lives in the php script that generates an HTML page then it is long
gone by the time a viewer of that HTML page requests, somehow, that the
string should be downloaded.

If it lives in the php script that executes as a result of a viewer
requesting, somehow, that the string be downloaded then simply output the
required headers that a browser would expect if, say, a .rtf file were to be
requested, followed by the contents of the string. The easyiest way to
determine what headers should be sent is to cause your browser to actually
download a file (something.rtf) and then examine the headers the server sent
using firebug or something. Never done this but that is the approach I would
take to make it happen.

--
Richard.
rf [ Do, 05 Juli 2007 12:58 ] [ ID #1760494 ]

Re: String to downloadable file.

"rf" <rf [at] invalid.com> schreef in bericht
news:h94ji.3605$4A1.767 [at] news-server.bigpond.net.au...
>
> "Maurice van 't Loo" <maurice [at] lievergeenspam.nl> wrote in message
> news:468cc8f9$0$89292$dbd4d001 [at] news.wanadoo.nl...
>> Hi All,
>>
>> I have a string with text and want to be able to download the string as a
>> file.
>> I browsed php.net, but cant find any clou....
>>
>> I do NOT want to write the string to a file what you can download
>> afterwards...
>> The file might be .txt, .rtf or something like that.
>>
>> Can anyone help me with this?
>
> Where does this string live?
>
> If it lives in the php script that generates an HTML page then it is long
> gone by the time a viewer of that HTML page requests, somehow, that the
> string should be downloaded.
>
> If it lives in the php script that executes as a result of a viewer
> requesting, somehow, that the string be downloaded then simply output the
> required headers that a browser would expect if, say, a .rtf file were to
> be requested, followed by the contents of the string. The easyiest way to
> determine what headers should be sent is to cause your browser to actually
> download a file (something.rtf) and then examine the headers the server
> sent using firebug or something. Never done this but that is the approach
> I would take to make it happen.
>
> --
> Richard.
>

It worked :-)

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=macros-cache.txt " );
header("Content-Transfer-Encoding: 8bit");
echo $bestand;
exit;

Thanks to your answer I could use the right words in Google :-p

Thanks for your fast answer :-)
Maurice
Maurice [ Do, 05 Juli 2007 14:36 ] [ ID #1760495 ]
PHP » alt.php » String to downloadable file.

Vorheriges Thema: Php ssh
Nächstes Thema: PHP4 and PHP5 together on 1 LAMP