Welcome Guest, Not a member yet? Register   Sign In
File Downloading Problem

Hi. I want to download a pdf file with I've generated. But this is not work.
function index()
      echo anchor('test/get_pdf','download');
  function get_pdf()
      $data = file_get_contents("./filename.pdf"); // Read the file’s contents
      $name = 'filename.pdf';
      force_download($name, $data);

   function generate_pdf()
       $this->mpdf->WriteHTML('<p>Hallo World</p>');

Did you load the 'download' helper file?


Also, are you generating the pdf first then downloading it? One way to narrow down your problem is to upload an already created PDF file to the server and point to it correctly in your get_pdf() function. If this works correctly, then its a problem with your PDF creation method/function.

The loadnig download library is in my constructor. The function generate_pdf is works. When I call a get_pdf there is on errors. But there is no downloaded file on my desktop too.

[eluser]Cristian Gilè[/eluser]
Check the generated pdf path. According to this line:

$data = file_get_contents("./filename.pdf");

the pdf file is at the same level of the front controller (index.php)

Cristian Gilè

Nice tip, had the same problem.



how the path shoould look like if a have a my file under CI folder??

[quote author="penta997" date="1297369607"]how the path shoould look like if a have a my file under CI folder??[/quote]

You probably shouldn't do it like that, but this might work:

$data = read_file("./system/file.pdf");

didn't work too...

[quote author="penta997" date="1297397016"]didn't work too...[/quote]

Then, what is the full path to the file? Is your host a Linux flavor, or Windows?

now my file is in CI folder. './ksiegarnia/CI'. And my OS is Windows.

Theme © iAndrew 2016 - Forum software by © MyBB