Welcome Guest, Not a member yet? Register   Sign In
force pdf download

when i click on a pdf link (the value is help in the db, $data['content_pdf'] = $row->content_pdfWink it tries to open the link as a web page rather than getting a "save as" pop-up.

any ideas?


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.




[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.

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:
$filename = 'somefile.pdf';
$filepath = '/some/path/';
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past to avoid cached files
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$filename}");
header("Content-Transfer-Encoding: binary");

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.

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!

Theme © iAndrew 2016 - Forum software by © MyBB