note 23364 added to function.header
| From: | gilux at xs4all dot nl | Date: | Tue, 16 Jul 2002 17:18:21 +0000 |
| Subject: | note 23364 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33158@lists.php.net to get a copy of this message | ||
well,
i spend 3 full days now trying to understand why IE 5.5 and IE6 cant handle the following code when
using the POST method:
====================================================
<?
if(@$_POST["submit"]){
$file_name="mypdf.pdf";
header("Content-type:application/pdf");
header("Content-Disposition: inline; filename=\"mypdf.pdf\"");
header("Content-length:".(string)(filesize($file_name)));
header("location: $file_name");
exit();
}
?>
<form method=post>
<INPUT TYPE="submit" name=submit value=bbb>
</form>
====================================================
and i still haven't figured out why.
it is suppost to output a pdf file to the browser.
however, i discovered that IE handles it correctly when using the GET method instead of the POST
method (netscape handles it correctly either way)
so, all i can suggest to people who wan't to display pdf files in IE and use a form in their
page,
use the GET method instead of the POST method!
with GET it works just fine, with POST it won't work
i also tried this:
but with negative results also:
====================================================
<?
error_reporting(E_ALL);
if(isset($_POST["download"])){
$file_name=$_POST["download"];
$fp = @fopen($file_name,"rb");
if ($fp!=NULL) {
header("Content-type:application/octetstream");
header("Content-Disposition: inline;filename=\"mypdf.pdf\"");
header("Content-length:".(string)(filesize($file_name)));
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
header('Expires: 0');
fpassthru($fp);
fclose($fp);
}
exit();
}
?>
<form method=post>
<INPUT TYPE="submit" name=download value="mypdf.pdf">
</form>
====================================================
tested with php4.2.1 on win2000/IIS5, win2000/apache and linux/apache
--
http://www.php.net/manual/en/function.header.php
http://master.php.net/manage/user-notes.php?action=edit+23364
http://master.php.net/manage/user-notes.php?action=delete+23364
http://master.php.net/manage/user-notes.php?action=reject+23364