【发布时间】:2015-07-26 16:18:55
【问题描述】:
我正在尝试从 mysql 中提取 BLOB 并将其发送给请求者,而不将其保存在服务器上。我已经让它处理 PDF 文件,但我们的一些客户想要 xls 文件。获取xls文件时,下载的文件是垃圾。在 HxD 中,它看起来像是在文件前面增加了 11 个字节。
这是我的代码,工作和不工作:
function blob_download_xls() {
$mysqli = openMySQLconnetion();
$sql = "SELECT * FROM Uploads;";
$results = $mysqli->query($sql);
$row = $results->fetch_assoc();
$bytes = $row['filedata'];
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="report.xls"');
print $bytes;
}
function blob_download_pdf() {
$mysqli = openMySQLconnetion();
$sql = "SELECT * FROM Uploads;";
$results = $mysqli->query($sql);
$row = $results->fetch_assoc();
$bytes = $row['filedata'];
header("Content-type: application/pdf");
header('Content-Disposition: inline; filename="report.pdf"');
print $bytes;
}
知道我做错了什么吗?
【问题讨论】: