1
我得到一個「壞網關錯誤502」嘗試下載服務器生成的.zip文件「壞網關錯誤502」嘗試下載時,服務器生成的.zip文件
我已經當孤立導致錯誤的行;它是:
$zip->addFile($thumb->loadVersion($version['id']), $rank . "_" . $thumb->filename);
這是我的代碼。我的腳本遍歷用戶上傳的所有.jpg文件,將它們捆綁到一個大的.zip文件中,併爲.zip文件發送下載標頭。
function downloadGalleryZip() {
$tmpfile = tempnam("tmp", "zip");
$zip = new ZipArchive();
$res = $zip->open($tmpfile, ZipArchive::OVERWRITE);
if ($res === TRUE) {
// loop through gallery
$sql = "SELECT * FROM files_versions WHERE file_id = ". $this->fileId . " AND deleted_on IS NULL ORDER BY rank ASC";
$result = db_query($sql);
$rank = 0;
while ($version = mysql_fetch_array($result)) :
$rank ++;
$rank = str_pad($rank, 3, '0', STR_PAD_LEFT);
$thumb = new fancyFile();
$zip->addFile($thumb->loadVersion($version['id']), $rank . "_" . $thumb->filename);
endwhile;
// $zip->addFromString('000_info.txt', 'Dieser Ordner wurde am ' . date("d.m.Y", time()) . ' heruntergeladen.');
$zip->close();
}
$filename = getCaptionFromFile($this->fileId) . ".zip";
header("Connection: Keep-Alive");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Type: application/zip");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length:' . filesize($tmpfile));
ob_clean();
flush();
}
我絕對跟「壞網關錯誤」沒有經驗,你的幫助是非常讚賞!
謝謝, 馬特