odf download problem in IE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

odf download problem in IE

Post 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
buttie
Forum Newbie
Posts: 2
Joined: Tue Dec 19, 2006 12:56 pm

Post 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
Post Reply