simcoweb Posted January 28, 2007 Share Posted January 28, 2007 I want to provide a downloadable PDF file but the typical link to it simply opens it in a window. I want to force that file to be downloaded without having to ZIP it. Do I need to write a script to do this? If so, insight or ideas? Quote Link to comment Share on other sites More sharing options...
corbin Posted January 28, 2007 Share Posted January 28, 2007 Look at http://us3.php.net/header and read the last example. Quote Link to comment Share on other sites More sharing options...
tarun Posted January 28, 2007 Share Posted January 28, 2007 Well you could get lots of good ideas from [code]http://www.hotscripts.cpm/PHP/Scripts_and_Programs/index.html[/code]There Are Some Good Download Systems Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 28, 2007 Author Share Posted January 28, 2007 Thanks, Tarun, but I don't need a complete download system. It's one file in a protected directory. :)corbin, I see this header reference that looks like the one:header('Content-type: application/pdf');Which, according to the manual text, forces the download. Quote Link to comment Share on other sites More sharing options...
Orio Posted January 28, 2007 Share Posted January 28, 2007 I'd use:[code]<?php//$filename holds the filename, including the extensionheader("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($filename)."\";" );header("Content-Transfer-Encoding: binary");header("Content-Length: ".filesize($filename));@readfile($filename);exit();?>[/code]Orio. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 28, 2007 Author Share Posted January 28, 2007 Orio, i'm assuming with that extended code that it's also protecting the actual location of the file? Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 28, 2007 Share Posted January 28, 2007 Yes, the URL in the download box will be the script URL and the name displayed will be the filename without any directory association. Quote Link to comment Share on other sites More sharing options...
Orio Posted January 29, 2007 Share Posted January 29, 2007 If you dont want the file to accessible by http, you have to options (that I can think of):1) Put it in the root folder (outside of public_html / www / httpdocs or whatever your html folder is called), then tell your script the file is there and it will transfer the data.2) Put it in a folder which has a .htaccess that has this following line:[code]Deny from all[/code]This way, no one will be able to access your file directly (IE- via http), but your php scripts will be able to.Orio. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 29, 2007 Author Share Posted January 29, 2007 Thanks for that tip, Orio. But let me ask you a question. The fact that the file is already inside an .htaccess protected 'members-only' folder, wouldn't that prohibit anyone from directly accessing it? Quote Link to comment Share on other sites More sharing options...
Orio Posted January 29, 2007 Share Posted January 29, 2007 You mean that you need a user-pass to access the folder? In this case, if someone has the user-pass combination he can access it directly.Orio. 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.