bsamson Posted December 5, 2006 Share Posted December 5, 2006 Alight. I have a 'forced download' script that I have made my own ... Here's how it works ...I have all my .pdf files located in the docs directory. So ... I have links on the Documents page that look like this: http://internal.mydomain.com/scripts/fd-pdf.php?f=3. The 3 is the name of the file. All of the documents in the 'docs' directory are pdf files. So I have the following script:fd-pdf.php[code]<?php$fn = $_GET[f].".pdf";$fullname = "http://internal.mydomain.com/docs/$fn";header("Content-Length: " . filesize($fullname));header('Content-Type: application/pdf');header("Content-Disposition: attachment; filename=".$fullname);readfile($fullname); // echo $fullname;?>[/code] I have echoed the $fullname and I know that it is correct. BUT when I click the link IE tries to download fd-pdf. Can I please get some guidance. Thanks! Link to comment https://forums.phpfreaks.com/topic/29534-force-download-script-issue/ Share on other sites More sharing options...
Orio Posted December 5, 2006 Share Posted December 5, 2006 Add these lines to your script:[code]<?phpif(ini_get('zlib.output_compression')) //Required for IE ini_set('zlib.output_compression', 'Off');header("Pragma: public"); //Some browsers require thisheader("Cache-Control: private",false); //Some browsers require thisheader("Content-Transfer-Encoding: binary");?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/29534-force-download-script-issue/#findComment-135534 Share on other sites More sharing options...
bsamson Posted December 5, 2006 Author Share Posted December 5, 2006 Orio, alright new script looks like this:[code]<?php$fn = $_GET[f].".pdf";$fullname = "http://internal.mydomain.com/docs/$fn";if(ini_get('zlib.output_compression')) //Required for IE ini_set('zlib.output_compression', 'Off');header("Pragma: public"); //Some browsers require thisheader("Cache-Control: private",false); //Some browsers require thisheader("Content-Transfer-Encoding: binary");header("Content-Length: " . filesize($fullname));header('Content-Type: application/pdf');header("Content-Disposition: attachment; filename=" . $fullname);readfile($fullname); // echo $filename;?>[/code] And still IE tried download the php file, fd-pdf.php. Any suggestions? Could it be this line: header("Content-Disposition: attachment; filename=" . $fullname); ? Thanks! Link to comment https://forums.phpfreaks.com/topic/29534-force-download-script-issue/#findComment-135554 Share on other sites More sharing options...
Orio Posted December 5, 2006 Share Posted December 5, 2006 Yes- you dont need the full name, only the reletive path.Orio. Link to comment https://forums.phpfreaks.com/topic/29534-force-download-script-issue/#findComment-135559 Share on other sites More sharing options...
bsamson Posted December 5, 2006 Author Share Posted December 5, 2006 I cant figure this out ... it still isn't working ... any other suggestions ... Link to comment https://forums.phpfreaks.com/topic/29534-force-download-script-issue/#findComment-135580 Share on other sites More sharing options...
Orio Posted December 5, 2006 Share Posted December 5, 2006 This is the script I use, it works both for IE and Mozilla. I made a few changes to make it good for your needs:[code]<?php$path = "docs/"; //put here the relative path from the script to the files$filename = $path.$_GET['f'].".pdf";if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');$ctype="application/pdf";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: $ctype");header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );header("Content-Transfer-Encoding: binary");header("Content-Length: ".filesize($filename));@readfile("$filename");exit();?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/29534-force-download-script-issue/#findComment-135589 Share on other sites More sharing options...
bsamson Posted December 5, 2006 Author Share Posted December 5, 2006 Hmmm ... wonder what was wrong w/ mine. Anyway, as usual, works PERFECT orio! Cant thank you enough! Link to comment https://forums.phpfreaks.com/topic/29534-force-download-script-issue/#findComment-135629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.