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

[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';
$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($filepath.$filename);

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)


Messages In This Thread
force pdf download - by El Forum - 08-07-2007, 04:50 AM
force pdf download - by El Forum - 08-07-2007, 06:37 AM
force pdf download - by El Forum - 08-07-2007, 10:36 AM
force pdf download - by El Forum - 10-10-2007, 07:44 PM
force pdf download - by El Forum - 10-18-2007, 09:57 AM
force pdf download - by El Forum - 10-18-2007, 02:10 PM
force pdf download - by El Forum - 10-18-2007, 02:31 PM
force pdf download - by El Forum - 12-15-2007, 07:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB