marf Posted May 22, 2007 Share Posted May 22, 2007 I have a pdf file lets say http://www.mydomain.com/mypdf.PDF and I have a hyperlink to it. When the user clicks on it Adobe automatically opens it up in the browser (as it should I guess). However I want to make it force the popup window to download, and not open it in the browser. I'm assuming I have to use a seperate download page where I pass the filename to a header and such, is that how I would do that? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 22, 2007 Share Posted May 22, 2007 try this <?php function forceDownload($archiveName) { $headerInfo = ''; // Security checks if( $archiveName == "" ) { echo "<html><title>PDF - Download </title><body><BR><B>ERROR:</B> The download file was NOT SPECIFIED.</body></html>"; exit; } elseif ( ! file_exists( $archiveName ) ) { echo "<html><title>PDF - Download </title><body><BR><B>ERROR:</B> File not found.</body></html>"; exit; } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename=".basename($archiveName).";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($archiveName)); readfile("$archiveName"); } WARNING: nothing must be printed to the script before headers, also DOUBLE check the file your downloading this will download anything you point it to.. so it might be woth checking the type is PDF Note: i know this is a php script but it might help :/ Quote Link to comment Share on other sites More sharing options...
marf Posted May 22, 2007 Author Share Posted May 22, 2007 Thanks Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 23, 2007 Share Posted May 23, 2007 solved ? if so please click solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.