【发布时间】:2011-08-26 00:28:49
【问题描述】:
我创建了一个数据库,其中包含一个包含 Blob 的表,我在其中保存了 ZIP 和 PDF 文件。问题是,我怎样才能让这些文件准备好通过 PHP 脚本下载?
【问题讨论】:
-
你为什么要在 MySQL 中存储二进制数据?
我创建了一个数据库,其中包含一个包含 Blob 的表,我在其中保存了 ZIP 和 PDF 文件。问题是,我怎样才能让这些文件准备好通过 PHP 脚本下载?
【问题讨论】:
像这样:
$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;
【讨论】: