Zip files in php

<?php
$filePath = '/path/to/store/zip/in/';
$zip = new ZipArchive();
$download = "{$filePath}download.zip";
$zip->open($download, ZipArchive::CREATE);
foreach (glob($filePath . "*.jpg") as $file) {
    #add it to the zip
    $zip->addFile($file);
}
$zip->close();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename = download.zip");
header('Content-Length: ' . filesize($download));
readfile($download); 

Leave a Reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.