Page 1 of 1

Problem when opening a download in IE

Posted: Mon Nov 06, 2006 6:57 am
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

Posted: Mon Nov 06, 2006 7:28 am
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';
}