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

[eluser]penta997[/eluser]
Hi. I want to download a pdf file with I've generated. But this is not work.
Code:
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->load->library('mpdf');
       $this->mpdf->WriteHTML('<p>Hallo World</p>');
       $this->mpdf->Output('filename.pdf','F');
   }
#2

[eluser]Jaketoolson[/eluser]
Did you load the 'download' helper file?

Code:
$this->load->helper('download');

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.
#3

[eluser]penta997[/eluser]
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.
#4

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

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

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



Cristian Gilè
#5

[eluser]Unknown[/eluser]
Nice tip, had the same problem.

Thanks

Lizo
http://www.dfg-espelkamp.de
#6

[eluser]penta997[/eluser]
how the path shoould look like if a have a my file under CI folder??
#7

[eluser]elverion[/eluser]
[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:

Code:
$data = read_file("./system/file.pdf");
#8

[eluser]penta997[/eluser]
didn't work too...
#9

[eluser]elverion[/eluser]
[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?
#10

[eluser]penta997[/eluser]
now my file is in CI folder. './ksiegarnia/CI'. And my OS is Windows.




Theme © iAndrew 2016 - Forum software by © MyBB