Codeigniter ZIP file download corrupted

download multiple file as zip in codeigniter
create and download zip file in codeigniter
this->load->library('zip)

I Am using the standard CI zip library to read a directory and create a zip file for downloading however when I am testing this in windows I get:

and in OS X the zip unpacks a cpgz file which then unpacks to a zip file - infinitely

My CI function:

public function downloadPackage($unique) {
    $this->load->library('zip');
    $text = $this->syndication_m->getTextForContent($unique);

    $path = '/var/www/html/uploads/'.$unique.'/';

    if(file_exists($path."copy-".$unique.".txt")) {
        unlink($path."copy-".$unique.".txt");
        $fp = fopen($path."copy-".$unique.".txt","wb");
        fwrite($fp,$text);
        fclose($fp);
    }

    $this->zip->read_dir($path);
    $this->zip->download('dl-'.$unique.'.zip');
}

Can anyone help me with a fix or suggest what to do here? Thanks

EDIT

public function downloadPackage($unique) {
    $this->load->library('zip');
    $path = '/var/www/html/uploads/'.$unique.'/';

    $text = $this->syndication_m->getTextForContent($unique);
    $this->zip->read_dir($path, TRUE);
    $this->zip->add_data('copy-'.$unique.'.txt', $text->synd_text);
    $this->zip->download('dl-'.$unique.'.zip');
}

php - Download Zip file corrupted in codeigniter, I'm using this function to create and download ZIP files. It works well for less than 200MB files, I tested. When I tried to download More than  I'm having the same problem with the zips that are created by the Zip lib. WinRar extracts them fine, but when I right click on any of the extracted files, Windows explorer crashes. Update: Quote:The files are fine when extracted with: 7-zip Native Windows Right-click option The files are corrupt when unzipped using: WinRar StuffIt

I have just come across a very similar issue where the downloaded zip file got corrupted and this is what solved my problem:

I call the ob_end_clean() function just before the $this->zip->download() line.

Php force download zip file corrupted - PHP, Hello everyone. I'm trying to force a zip-file's download after some checks ( hash , expiration date, download's number ) . The link of the page  CodeIgniter already provided a zip library that allows either add files or a directory for Compress. Need to load the zip library for using it. In this tutorial, I show how you can create a zip file, download, and save it to the server with CodeIgniter.

In place of writing file using fopen try to use "$this->zip->add_data($text);" and make sure directory(sub directories) $path pointing to does not have any soft link(shortcuts) files.

Apart from this try, not to include empty folders in zip file sometimes it creates these kind of issues.

download helper does not work on zip file?, download helper force download function, it work (thanks to CI) but the problem is, zip and film file is always corrupt went someone download  How to zip, save, download a file in codeigniter. In this article we are going to see how to zip, save, download a file in codeigniter PHP framework. codeigniter is a very popular PHP framework. Previous article is about how to upload a file using codeigniter PHP framework. Codeigniter framework you can do many tasks very easily.

I had similar issue. whenever i was creating new zip file and unzipping .zip file, new file was creating as .cpgz. this was happening due to my zip file was not creating properly. Means it was creating as corrupt zip file.

Meanwhile i was getting Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) error. Once i solved this Fetal error, my zip and unzip issue got resolved.

I resolved below error

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes)

Add into index.php

ini_set('memory_limit', '-1');

"The compressed (zip) folder is invalid or corrupted" error after , I have a zip archive of ~250Mb located on an Apache HTTP server. Several users have complained of a "corrupt zip folder" after downloading  CodeIgniter 3. CodeIgniter 3.1.11 is the current version of the framework, intended for use with PHP 5.6+. There have been a number of refinements since version 2, notably with the database, session handling and encryption. Development of this version is ongoing. Download

Dowload helper problem with corrupted .7z and .rar files, I am using Codeigniter's Download helper for “easy” downloading. and rar files to become corrupt, while having no effect on the zip files for  Zip Encoding Class¶. CodeIgniter’s Zip Encoding Class permits you to create Zip archives. Archives can be downloaded to your desktop or saved to a directory.

Download results in a corrupt Zip file for some and not for others , There have been reported and validated instances where a downloaded Zip file will open correctly for some users, while others who download the same Zip file  CodeIgniter-Unzip. Extract ZIP files in CodeIgniter without installing any PECL extensions for PHP. Requirements. PHP 5.1+ CodeIgniter 1.6.x - 2.0-dev

ZipArchive - Manual, Available for closed archive, as of PHP 8.0.0 and PECL zip 1.18.0. It happily decompressed corrupt files in my tests and the user downloading the data is not  GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. force_download() used with

Comments
  • Maybe this can help: ellislab.com/forums/viewthread/111977
  • Hi I have just tried all of this an still not working correctly.
  • i also tried the example that i gave you and worked as expected. Can you please show what is the value of $unique and what $this->syndication_m->getTextForContent() is returning!?
  • $unique = 4ts5yegq; and text is equal to a string of text I have made a change here to $text->synd_text;
  • Updated my question with a new snippet as per your answer
  • please try the function in my edit, just copy/paste, and let me know if it works properly ...
  • Works brilliantly. ob_end_clean == "clean/clear output buffer"
  • This only happend when I created big ZIP files (more than 250 files, 50MB), using ob_end_clean() solved the issue. Thanks Peter!