force pdf download |
[eluser]webdude[/eluser]
when i click on a pdf link (the value is help in the db, $data['content_pdf'] = $row->content_pdf it tries to open the link as a web page rather than getting a "save as" pop-up. any ideas?
[eluser]Crimp[/eluser]
http://ellislab.com/codeigniter/user-gui...elper.html
[eluser]LuckyFella73[/eluser]
Did I get it right that the sourcecode of the "PDF file" is an entry in your DB? Then maybe you'll have to use the download helper additionally (after creating the pdf file from your DB). So you could first write the file, use the download-helper and delete the file after the download is complete. The CI download helper is great but in case your file is too large it won't work anymore - I think it's because of the PHP memory limit. Just wanted to mention it because I had the same problem a while ago. Cheers, Luckyfella http://ellislab.com/codeigniter/user-gui...elper.html
[eluser]Bacteria Man[/eluser]
When Adobe Acrobat (Reader) is installed this is usually the desired and expected behavior. An easy workaround is to zip the PDF.
[eluser]easymind[/eluser]
In my previous post here I deleted this because I didn't know the force_download() helper function from CI. But CI wants you to put the data in a variable first. So maybe this still is interesting: Code: $filename = 'somefile.pdf'; Readfile directly dumps the data. So maybe you won't get the problem of the memory limit in PHP. Otherwise you can read and dump a file part by part yourself with fopen wrappers... Then again.... You have the file data in the db, so you probably have to put the data in a variable. If you want it that way for security I can advice you to put files in a folder outside your webroot and use the above code in a function to let people download the files and maybe do a user check first. This way you do not have direct urls to your files but still can have files that are bigger than 8mb (standard PHP memory limit size? or 16mb...don't know)
[eluser]Bacteria Man[/eluser]
You know, that's pretty cool. I haven't ever needed to do that before, but it's bound to come in handy. Thanks very much for bringing it to my (our) attention.
[eluser]jabbett[/eluser]
easymind-- Thanks for this bit of code... using force_download was appending a whole bunch of empty lines at the beginning of my PDF, and Foxit/Acrobat couldn't parse it. Your code did the trick! |
Welcome Guest, Not a member yet? Register Sign In |