You can create the ZipArchive
and then add the image(s) from a loop using addFromString()
method. I use snippet from both your source codes below. The database connection logic is left out for simplicity reasons.
$zip = new ZipArchive();
$ZipFileName = "newZipFile.zip";
if ($zip->open($ZipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true)
{
echo "Cannot Open for writing";
}
$zip->addEmptyDir('newFolder');
$query = mysql_query("SELECT * FROM tbl_images WHERE ID ='".$id."' ");
while($row = mysql_fetch_array($query))
{
$zip->addFromString( $row['image_name'], $row['image']);
}
$zip->close();