Asuraya Asuraya - 6 months ago 94
PHP Question

Codeigniter Zip Encoding read_file is not working

I want to make and download archive from my existing files. I tried to following code.

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

$this->zip->download('my_backup.zip');


But this code is not working. But when i use following code it is working.

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

$this->zip->download('my_backup.zip');


I can use this code. But i think it is not best way to do this works. Because i no need add data to file. Please help me. What is the best way to do that?




Edit

Suddenly It is works. But now second code is not working. :( What is the issue?

Answer

The CodeIgniter zip library is broken, and the framework is no longer being maintained. read_file() doesn't work very well. Use add_data().

add_data() takes two params:

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

In practice, this would be:

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