![]() |
Forcing download PDF Files not working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Forcing download PDF Files not working (/showthread.php?tid=5459) |
Forcing download PDF Files not working - El Forum - 01-22-2008 [eluser]Isern Palaus[/eluser] Hello, I'm trying to force download PDF Files from a controller. In the administration of the website that I'm programing it's possible to add PDF files. Well, in the public version it needs to be download and I tried this: Code: function getRevista() The filename usually will be asked in the DB but now, for the proof of concept I use a specific name. The uploaded files are in ./public_html/revistes/ my aplication folder is ./application/ and the system is ./system/. When I try to get the file Adobe Reader gives me a error like: Quote:Acrobat could not open '2b07f.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly uploaded. When I checked the file for the size i saw that it's not a 0 bytes files. It contains the URL to the download, like this: http://argentona.ipalaus.es/revistes/2b07f.pdf What can I do? Thank you in advance and sorry for school English. Regards, -- Isern Palaus Forcing download PDF Files not working - El Forum - 01-22-2008 [eluser]Isern Palaus[/eluser] What's more, what I want is that the user can't never know the real URL to the file. By the way, it's possible to put the files before the public_html folder? And force a download to it like /home/ipalaus/iesargentona/revises/2b07f.pdf for the controller in: /home/ipalaus/iesargentona/application/controllers/main.php and the site: /home/ipalaus/iesargentona/public_html/index.php Sorry for double replying. Regards, -- Isern Palaus Forcing download PDF Files not working - El Forum - 01-23-2008 [eluser]dawnerd[/eluser] It is very possible and gave me much trouble when I first attempted it. Code: function _readfile_chunked($filename,$retbytes=true) { That's the best way in case you have a larger pdf. As for the path, it is relative to the CI root. Meaning if it is below pub_html then you must use ../downloads/file. In the class I supplied above, the first parameter is the path to the file with the filename at the end. I hope this helped. Forcing download PDF Files not working - El Forum - 01-23-2008 [eluser]Alex007[/eluser] force_download() 2nd parameter must be the file CONTENT, not the file name. Read your whole PDF in a string variable, then pass that to force_download(). Re-read the user guide, there's a perfect example in there. |