Showing posts with label Php Zip Archive. Show all posts
Showing posts with label Php Zip Archive. Show all posts

Wednesday, December 5, 2012

Php make zip file

$zip = new ZipArchive();
$zipFileDir = "c:/src/";
$zipFileName = "test.zip";
$zip->open($zipFileDir.$zipFileName, ZIPARCHIVE::CREATE);

/* FROM FOLDER c:/files/ */
$zipIncludedFilesDir = "c:/files/";
chdir($zipIncludedFilesDir);
$zip->addFile("a.jpg");
$zip->addFile("b.jpg");
$zip->close();
if(file_exists($zipFileDir.$zipFileName)) {
    header('Content-Type: application/zip');
    header('Content-disposition: attachment; filename='.$zipFileName);
    header('Content-Length: ' . filesize($zipFileDir.$zipFileName));
    readfile($zipFileDir.$zipFileName);
    unlink($zipFileDir.$zipFileName);
}
exit;