cakephp


How to create Zip file and add image or file in zip file

public function downloadimages($userid,$orderid) {
$this->layout=””;
$data = $this->userorderdata($userid,$orderid);

if(extension_loaded(‘zip’))
{

$data = $this->Image->find(‘all’,array(‘conditions’=>array(‘Image.order_id’=>$orderid,’Image.user_id’=>$userid)));

$file_folder = “fullpath/eliteretouch/img/”;
// Checking ZIP extension is available
if(isset($data) and count($data) > 0)
{
$zip = new ZipArchive(); // Load zip library
$zip_name = fullpath/eliteretouch/img/’.time().”.zip”;
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE)
{
$error .= “* Sorry ZIP creation failed at this time”;
}
foreach($data as $file)
{
$aaa = $zip->addFile($file_folder.’fullpath/eliteretouch/img/upload/’.$file[‘Image’][‘image_name’]); // Adding files into zip
}
$zip->close();
if(file_exists($zip_name))
{
// push to download the zip
header(‘Content-type: application/zip’);
header(‘Content-Disposition: attachment; filename=”‘.$zip_name.'”‘);
readfile($zip_name);
unlink($zip_name);
}

}
}