Using the Codeigniter Helper (Download_helper)

0

Good evening! I'm using the force_download() function to download a file. However, I need to do the same procedure, but with several files downloaded at the same time. I implemented a code, the logic I used is not performing such a procedure. Can anyone give me a hint of what I can do?

Controller:

 public function download($id = NULL){
    $this->load->helper('download');
    $download = $this->db->query('SELECT * FROM arquivos WHERE protocolo_id ='.$id);
    foreach ($download->result() as $itens){
        $diretorio = file_get_contents('./uploads/'.$itens->arquivo);         
        $arquivo = $itens->arquivo;
        force_download($arquivo, $diretorio);      
    }  
}        
    
asked by anonymous 21.04.2015 / 01:55

1 answer

1

What I recommend to you is to use the library Zip to add your files to a compressed file and then download them: Below your function in a similar way, which I believe meets your needs:

public function download($id = NULL){
    $this->load->library('zip');

    $download = $this->db->query('SELECT * FROM arquivos WHERE protocolo_id ='.$id);

    foreach ($download->result() as $itens){
        $this->zip->add_data('./uploads/'.$itens->arquivo, file_get_contents('./uploads/'.$itens->arquivo));
    }

    if($download->num_rows() > 0){
        $this->zip->archive('/path/arquivos.zip');
        $this->zip->download('arquivos.zip');
    }
}
    
21.04.2015 / 02:52