CodeIgniter - force_download () no output

Quickly explain, but I can't get it to work:

In this simple code, the force_download function simply does not produce any output.

$this->load->helper('download'); $data = file_get_contents("modulos/".$filename); // Read the file contents force_download($filename, $data); echo $data."/".$filename; 

Here I just get a white screen, but the contents of the file are displayed (well, you know, weird codified content :) I think it’s quite simple, I just want the file to load without any other effect, I’m doing something wrong ?

+6
php codeigniter download
source share
4 answers

Just pay attention to someone who might have this problem: make sure you have the file extension for the file name that you specified for the first force_download() argument.

CodeIgniter uses this to set the MIME type, and it does not seem to work.

+3
source share

It will work with you

 $this->load->helper('download'); $path = file_get_contents(base_url()."modulos/".$filename); // get file name $name = "sample_file.pdf"; // new name for your file force_download($name, $path); // start download` 
+2
source share

Delete echo $data."/".$filename; It should be like

  $ this-> load-> helper ('download');
 $ data = file_get_contents ("modulos /".$ filename);  // Read the file contents
 force_download ($ filename, $ data); 
0
source share

You should not call the function after force_download (), just delete the last line.

0
source share

All Articles