Welcome Guest, Not a member yet? Register   Sign In
Forcing download PDF Files not working
#3

[eluser]dawnerd[/eluser]
It is very possible and gave me much trouble when I first attempted it.

Code:
function _readfile_chunked($filename,$retbytes=true) {
       $chunksize = 1*(1024*1024); // how many bytes per chunk
       $buffer = '';
       $cnt =0;
       // $handle = fopen($filename, 'rb');
       $handle = fopen($filename, 'rb');
       if ($handle === false) {
           return false;
       }
       while (!feof($handle)) {
           $buffer = fread($handle, $chunksize);
           echo $buffer;
           ob_flush();
           flush();
           if ($retbytes) {
               $cnt += strlen($buffer);
           }
       }
           $status = fclose($handle);
       if ($retbytes && $status) {
           return $cnt; // return num. bytes delivered like readfile() does.
       }
       return $status;
    
    }

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.


Messages In This Thread
Forcing download PDF Files not working - by El Forum - 01-22-2008, 11:09 AM
Forcing download PDF Files not working - by El Forum - 01-22-2008, 11:12 AM
Forcing download PDF Files not working - by El Forum - 01-23-2008, 01:16 AM
Forcing download PDF Files not working - by El Forum - 01-23-2008, 07:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB