Re: Downloading a .txt file...
| From: | Monte Ohrt | Date: | Wed, 18 Oct 2000 15:01:06 +0000 |
| Subject: | Re: Downloading a .txt file... | ||
| References: | 1 2 | Groups: | php.pear |
| Request: | Send a blank email to php-pear+get-407@lists.php.net to get a copy of this message | ||
This is a bit off topic for PEAR, but I think I know the answer to this
one.
In your Apache config directory, there is a "mime.types" file. In here,
you will find that the default mime-type for .txt files is "text/plain".
By default, most browsers are setup to handle this mime-type by
displaying it. If you want a file requestor to come up, you have to
either change your browser's behavior for this mime-type, or change the
mime-type on the server for the .txt file extention.
If you want all .txt files to pop up requestors for all visitors (so
they don't have to modify their browsers), you must change the mime-type
for .txt files in Apache. Change it from text/plain to something that
will cause a browser to pop up a file requestor. Maybe make one up, like
application/text and test it.
Monte
Steffen Uhlig wrote:
>
> Edward Wong wrote:
>
> > Can anyone provide a better solution?
>
> I had a similar problem. I am providing pdf files for download, but I don't
> want to start the pdf viewer (acrobat or something similar) on the client
> side but rather save to file.
>
> I solved it by pointing from the link to another php page (download.php)
> instead of the real file:
>
> <a href="download.php">Download</a>
>
> download.php sends an extra header first and then the contents of the
> desired file. It looks like this:
>
> <?php
> // the name of the desired file for download is passed as
> // $filename (parameter, hidden form variable or session data)
>
> // most browsers will present a "Save As..." box for binaries
> header("Content-Type: application/octet-stream");
>
> // suggest a file name in the "Save As..." box
> header("Content-Disposition: inline; filename=$filename");
>
> // read the file and send it
> readfile($filename);
> ?>
>
> Remember that you can't have any output (not even a single whitespace or
> newline) in download.php before sending the last header.
>
> HTH
>
> Steffen
>
> --
> http://steffen-uhlig.de/
>
> --
> PHP Extension and Add-on Repository (PEAR) mailing list.
> Documentation can be found at http://pear.php.net/doc/pear.html
> To unsubscribe, e-mail: php-pear-unsubscribe@lists.php.net from the
> mail address you subscribed with.
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/