CodeIgniter - force_download() no output

前端 未结 5 656
情深已故
情深已故 2021-02-06 07:37

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

In this simple code, the function force_download simply doesn\'t make any output.

$this->load->helper         


        
相关标签:
5条回答
  • 2021-02-06 07:57

    Remove that echo $data."/".$filename; It should be like this

    $this->load->helper('download');
    $data = file_get_contents("modulos/".$filename); // Read the file's contents
    force_download($filename, $data); 
    
    0 讨论(0)
  • 2021-02-06 07:57

    remove base_url() and do like this

    $path= file_get_contents('./uploads/abc.jpg);
    
    0 讨论(0)
  • 2021-02-06 08:01

    You should not call function after force_download(), Just remove the last line.

    0 讨论(0)
  • 2021-02-06 08:06

    Just a note to anyone else who may be having this problem: Make sure you have a file extension on the filename you supply for the first argument to force_download().

    CodeIgniter uses this to set the MIME type, and it doesn't seem to work without.

    0 讨论(0)
  • 2021-02-06 08:11

    This 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`
    
    0 讨论(0)
提交回复
热议问题