Page 1 of 1

https/ssl header -> prompt and open file

Posted: Wed Nov 03, 2004 5:36 pm
by jakobdoppler
Hi

While trying to open or save a file with the prompted dialog initalized though phps header function in https mode I use following code.
- In Mozilla/Firefox downloading and instantly opening the file is working
- In IE i can only download the file, but not open it. (Adobe PDF) states that, while opening the file an error occured and that the file does not exist.

Code: Select all

<?php
$fd = @fopen ($path, "rb")
$name = basename($path);
$fsize=filesize($path);

header("Pragma: public");
header("Cache-Control: ");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Content-Type: application/pdf");
header("Content-Disposition:attachment; filename="".trim(htmlentities($name)).""");
header("Content-Description: ".trim(htmlentities($name)));
header("Content-Length: ".(string)$fsize);
header("Connection: close");

while(!feof($fd)) {
	$buffer = fread($fd, 4096);
	print $buffer;
} 
fclose( $fd);
?>
I tried to search phpManual on this, but it only comes up with ideas like opening the file "inline" or fixing a bug of older IE version (which i am definitely not using)
On contrary when I use these lines without SSL opening and saving works for both IE and Mozilla/Firefox

Code: Select all

<?php
$fd = @fopen ($path, "rb")
$name = basename($path);
$fsize=filesize($path);

header("Cache-control: private");
header("Content-Type: application/pdf");
header("Content-Disposition:attachment; filename="".trim(htmlentities($name)).""");
header("Content-Description: ".trim(htmlentities($name)));
header("Content-Length: ".(string)$fsize);
header("Connection: close");

while(!feof($fd)) {
  $buffer = fread($fd, 4096);
       print $buffer;
      } 
fclose( $fd);
?>
How could I fix this problem without having to read the whole RFC, is it normally recommended to open pdfs inline, and than save it directly from the pdf viewer?
Any comment appreciated, thanx _yak