Problem when opening a download 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

Problem when opening a download in IE

Post by hame22 »

Hi

I have set up a site where the user can download a pdf .

The code I am using is as folllows:

Code: Select all

$TJ_PDF_PATH = '/usr/local/home/httpd/vhtdocs/host/web/assets/news/ '; 

$path     = $TJ_PDF_PATH . $news_pdf; 
        
        
        if (file_exists($path)) 
        { 
                $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"); 
        
} 
else { 
        print 'There was a problem with the download, please contact for assistance'; 
}
This works fine when I want to save the pdf to my system, however when I choose to open it Adobe acrobat launches and syas there is an error, saying the file could not be found. - This error is only expeirenced in IE

Could anyone help with this problem, I would be most grateful
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

$TJ_PDF_PATH = '/usr/local/home/httpd/vhtdocs/host/web/assets/news/ ';
$path     = $TJ_PDF_PATH . $news_pdf;
if ( file_exists($path) && !headers_sent() )
{
	$size   = filesize($path);
	$file   = basename($path);
	
	header("Content-Type: application/pdf");
	header("Content-Disposition: attachment; filename=$file");
	header("Content-Length: $size");
	readfile($path);
}
else {
	print 'There was a problem with the download, please contact for assistance';
}
Post Reply