ZIP IMAGE FILES (ARRAY) IN PHP
$dires = "/var/www/XXX/XXX/";
$d = dir($dires);
$zip = new ZipArchive();
$zipname = time().'xxxx.zip';
$zip->open($zipname, ZipArchive::CREATE);
$serverpath = $_SERVER['DOCUMENT_ROOT'].'xxx/xxxx/';
// print_r($serverpath);
//Images in Array ("xx/xxx.jpg", "mm/mmm.jpg", "nn/nnn.jpg" )
foreach ($pubnameimg as $singlefile)
{
$filename = basename($singlefile);
$filepath = dirname($singlefile);
$zipfilenames = $serverpath.$filepath."/$filename";
if(file_exists($zipfilenames))
{
// print_r($zipfilenames."
");
$zip->addFile($zipfilenames, $filename);
}
// print_r($filepath."");
}
$zip->close;
header('Content-Type: application/zip');
header('location:'.$zipname);
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
unlink($zipname);exit;
Comments
Post a Comment