Page 1 of 1

odf download problem in IE

Posted: Tue Dec 19, 2006 5:15 am
by hame22
Hi

I am using the following code to download a pdf from my website

Code: Select all

<?php

require_once('../includes/inc.functions.php');
session_start();

$paper_id = $_POST['paper_id'];
$filename = $_POST['filename'];

if(isset($_SESSION['valid_user']))
{
	global $PAPER_PATH;

	
	$path 		= $PAPER_PATH . $filename;
	
	//print $path;
	
	
	if (file_exists($path) && !headers_sent() ) 
	{
		$size 	= filesize($path);
		$file 	= basename($path);
		
		//header("Content-Type: application/octet-stream");
		//header("Content-Type: application/download");
		//header("Content-Disposition: attachment; filename=$file");
		//header("Content-Length: $size");
		//readfile($path);
		//header("Location: $path");
		header("Content-Type: application/pdf"); 
        header("Content-Disposition: attachment; filename=$filename"); 
        header("Content-Length: $size"); 
        readfile($path); 
	
}
else {
	print 'There was a problem with the download, please contact Training Journal for assistance';
}
}
?>

This works fine in firefox but in IE I can only save it, when I attempt to open it a error appears in acrobat saying "File cannot be found"

Does anyone see a problem with my method#?

Thansk in advance

Posted: Tue Dec 19, 2006 1:14 pm
by buttie
I know pdf downloads can be a real pain, and the header combination can be really picky on IE especially under sessions...try the following....

if the code you outlined is being called from a file e.g.

http://www.mysite.com/download.php

then append a variable (can be the name of the pdf file but doesn't really matter) .... so you would instead call...

http://www.mysite.com/download.php?var=myfile.pdf

the trick here is that IE tries to be clever seeing the file extension (which was previously .php) as .pdf so expects a pdf