<?php
include "include/config.inc.php";

/* Write here the name of the folder  where the zip will be created */
$sFolderZip = "zipfiles/";

     
/* Connecting to the server */
$db = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass'])
   or die (mysql_error());

/* Selecting the database */
$db_check = @mysql_select_db($CONFIG['dbname']);


/* Retrieving pictures list */
$sql = 'SELECT * FROM `'.$CONFIG['TABLE_PREFIX'].'pictures` where `aid` = ' . $aid;
$result = mysql_query($sql) OR die(mysql_error());
$bilder = "";
while ($row = mysql_fetch_assoc($result))
   $bilder .= "albums/" . $row['filepath'].$row['filename'].",";

/* Retrieving album name */
$sql = 'SELECT * FROM `'.$CONFIG['TABLE_PREFIX'].'albums` where `aid` = ' . $aid;
$result = mysql_query($sql) OR die(mysql_error());
$o_AlbumName = mysql_fetch_object($result);
$sDesiredZipName = urlencode($o_AlbumName->title);

/* Creating the zip file */
include_once('pclzip.lib.php');
$archive = new PclZip($sFolderZip.$sDesiredZipName . '.zip');
$v_list = $archive->create($bilder);
if ($v_list == 0)
	die("Error : ".$archive->errorInfo(true));


$file = $sFolderZip.$sDesiredZipName.".zip";
$filename = basename($file);
$size = filesize($file);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$filename);
header("Content-Length:".$size);
readfile($file);
?>