Codeigniter Zip Encoding read_file is not working


Codeigniter Zip Encoding read_file is not working

我想从现有文件中制作并下载归档文件。我试着遵循代码。

$this->zip->read_file('/upload/ut/10_33_statement.xls', true);
$this->zip->download('my_backup.zip'); 

但是这个代码不起作用。但当我使用以下代码时,它是有效的。

$this->zip->add_data('/upload/ut/10_33_statement.xls', '');
$this->zip->download('my_backup.zip'); 

我可以使用这个代码。但我认为这不是最好的方式来做这项工作。因为我不需要向文件中添加数据。请帮帮我。最好的方法是什么?


编辑

突然间,它起作用了。但现在第二个代码不起作用(问题出在哪里?

CodeIgniter zip库已损坏,不再维护该框架。read_file()工作不太好。使用add_data()。

add_data()采用两个参数:

$this->zip->add_data($fileName,$dataToAddInTheFile);

在实践中,这将是:

$this->zip->add_data('my_spreadsheet.xls', '/upload/ut/10_33_statement.xls');
$this->zip->download('my_spreadsheet.zip');

试试这个。。它对我有效

public function downloadall(){
        $createdzipname = 'myzipfilename';
        $this->load->library('zip');
        $this->load->helper('download');
        $cours_id = $this->input->post('todownloadall');
        $files = $this->model_travaux->getByID($cours_id); 
        // create new folder 
        $this->zip->add_dir('zipfolder');
        foreach ($files as $file) {
            $paths = 'http://localhost/uploads/'.$file->file_name.'.docx';
            // add data own data into the folder created
            $this->zip->add_data('zipfolder/'.$paths,file_get_contents($paths));    
        }
        $this->zip->download($createdzipname.'.zip');
    }