note 46615 added to function.header
| From: | foxyshadis at hotmail dot com | Date: | Sun, 17 Oct 2004 15:15:34 +0000 |
| Subject: | note 46615 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78697@lists.php.net to get a copy of this message | ||
To Jeremy:
The reason it was downloading was because you used
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
This is the generic "download and save me" content-type, and "Content-Disposition:
attachment" is specifically intended to pop up a save as box. I'm not sure how your hacks
got it to ignore that, but all you had to do was use text/plain or text/html and inline instead.
Please avoid adding bad hacks to work around your misunderstanding of the relevant rfcs to the php
manual.
A sane impl of your script:
<?php
$SRC_FILE = "/path/outside/web/server/test.txt";
$filename = basename($SRC_FILE);
header("Content-Type: text/plain");
header("Content-Disposition: inline; filename=$filename");
@readfile($SRC_FILE);
?>
There are additional considerations, like IE tending to ignore content-type and using the request
uri for the filename.
Trust the webserver to either add the content-length or ignore it, unless you absolutely have to
have pipelining for your pages.
----
Manual Page -- http://www.php.net/manual/en/function.header.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46615
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46615&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46615&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46615&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46615&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46615&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46615&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46615&report=yes
Search -- http://master.php.net/manage/user-notes.php