如何使Zip Blob文件准备好从MySQL数据库下载

时间:2011-08-26 00:28:50

标签: php mysql blob

我创建了一个数据库,其中包含一个包含blob的表,其中我保存了ZIP和PDF文件。问题是,如何通过PHP脚本准备好下载这些文件?

1 个答案:

答案 0 :(得分:2)

像这样:

$name = "file.zip"; // or file.pdf
$file_content = $blob_row['file_content'];

header('Content-Description: File Transfer');

header('Content-Type: archive/zip'); // or archive/pdf

header('Content-Disposition: attachment; filename=' . $name);

header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($file_content));
ob_clean();
flush();

echo $file_content;
exit;