我有一個數據庫表,其中包含大量的PDF blob文件。我試圖將所有文件合併到一個ZIP文件中,我可以下載並打印。Zip多個數據庫PDF blob文件
請幫忙!
<?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');
$files = array();
while(list($username, $description, $type, $size, $content) =
mysql_fetch_array($result)) {
$files[] = "$username-$description.pdf";
}
$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);
exit();
?>
爲什麼不是你當前的代碼工作?你有沒有收到任何錯誤信息? – 2010-06-11 18:07:12
它創建一個空的zip文件。 – Michael 2010-06-11 19:16:06
我想可能是文件路徑/目錄問題?另外,我是否需要blob條目的標題信息? header(「Content-length:$ size」); header(「Content-type:$ type」); header(「Content-Disposition:inline; filename = $ username- $ description.pdf」); – Michael 2010-06-11 19:20:49