CodeIgniter Forums
File Downloading Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: File Downloading Problem (/thread-38494.html)

Pages: 1 2


File Downloading Problem - El Forum - 02-09-2011

[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');
   }



File Downloading Problem - El Forum - 02-09-2011

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


File Downloading Problem - El Forum - 02-10-2011

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


File Downloading Problem - El Forum - 02-10-2011

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


File Downloading Problem - El Forum - 02-10-2011

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

Thanks

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


File Downloading Problem - El Forum - 02-10-2011

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


File Downloading Problem - El Forum - 02-10-2011

[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");



File Downloading Problem - El Forum - 02-10-2011

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


File Downloading Problem - El Forum - 02-10-2011

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


File Downloading Problem - El Forum - 02-11-2011

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