Thursday, 31 July 2014

How to create Zip file using php?

$zip = new ZipArchive();
$zip_name = time().".zip"; // Zip name
$zip->open($zip_name, ZipArchive::CREATE);
$zip->addFile('test.php');
$zip->close();
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_name);
unlink($zip_name);

No comments:

Post a Comment