ZipArchive not working

I am generating a zip file with the following code:

function create_zip($files = array(),$destination = ”,$overwrite = false) {
$valid_files = array();
if(is_array($files)) {
foreach($files as $file) {
if(file_exists($file)) {
$valid_files[] = $file;
if(count($valid_files)) {
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
echo “failed”;
return false;
foreach($valid_files as $file) {
echo $file;
header(“Content-disposition: attachment; filename=$destination”);
header(“Content-type: application/zip”);
return file_exists($destination);

And I’m calling it like this:

$zipFile = $username.’’;
create_zip($files, $zipFile);

Now, this works fine on my localhost but when live, it does not work. Does not throw me any error or warning. I tried printing values to see which line is having problem, seems to be that the program does not go any further than $zip = new ZipArchive();. Any suggestions to where I am doing it wrong?

Read more here:: ZipArchive not working

Leave a Reply

Your email address will not be published. Required fields are marked *