ZIP Numerous Blob Files
- by Michael
I have a database table that contains numerous PDF blob files. I am attempting to combine all of the files into a single ZIP file that I can download and then print.
Please help!
<?php
include 'config.php';
include 'connect.php';
$session= $_GET[session];
$query = "
SELECT $tbl_uploads.username, $tbl_uploads.description,
$tbl_uploads.type, $tbl_uploads.size, $tbl_uploads.content,
$tbl_members.session
FROM $tbl_uploads
LEFT JOIN $tbl_members
ON $tbl_uploads.username = $tbl_members.username
WHERE $tbl_members.session= '$session'";
$result = mysql_query($query) or die('Error, query failed');
while(list($username, $description, $type, $size, $content) =
mysql_fetch_array($result))
{
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: inline; filename=$username-$description.pdf");
echo $content;
}
$files = array('File 1 from database', 'File 2 from database');
$zip = new ZipArchive;
$zip->open('file.zip', ZipArchive::CREATE);
foreach ($files as $file) {
$zip->addFile($file);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=filename.zip');
header('Content-Length: ' . filesize($zipfilename));
readfile($zipname);
mysql_close($link);
exit;
?>