create and download zip file using php
codeigniter, download, php, zip
Solution
Why not use the Zip Encoding Class in Codeigniter - it will do this for you
$name = 'mydata1.txt';
$data = 'A Data String!';
$this->zip->add_data($name, $data);
// Write the zip file to a folder on your server. Name it "my_backup.zip"
$this->zip->archive('/path/to/directory/my_backup.zip');
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
https://www.codeigniter.com/user_guide/libraries/zip.html
Problem
i am trying to create a zip file(using php) for this i have written the following code: ``` $fileName = "1.docx,2.docx"; $fileNames = explode(',', $fileName); $zipName = 'download_resume.zip'; $resumePath = asset_url() . "uploads/resume/"; //http://localhost/mywebsite/public/uploads/resume/ $zip = new ZipArchive(); if ($zip->open($zipName, ZIPARCHIVE::CREATE) !== TRUE) { echo json_encode("Cannot Open"); } foreach ($fileNames as $files) { $zip->addFile($resumePath . $files, $files); } $zip->close(); header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=".$zipName.""); header("Content-length: " . filesize($zipName)); header("Pragma: no-cache"); header("Expires: 0"); readfile($zipName); exit; ``` however on a button click i am not getting anything..not even any error or message.. any help or suggestion would be a great help for me.. thanks in advance