我想从oracle下载blob文件,即PDF文件,这是我获取和下载文件的代码:
<?php
$conn = ocilogon('user', 'pass', '//localhost/XE');
$sql = "SELECT PDFFILE FROM TFILE";
$stid = ociparse($conn,$sql);
ociexecute($stid);
$rowResult = ocifetch($stid);
settype($arrayResult,"array");
if($rowResult != null){
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . OCIResult($stid,'PDFFILE') . '"');
header("Content-Length: " . filesize(OCIResult($stid,'PDFFILE')->load()));
header('Content-Disposition: attachment; header("Content-Transfer-Encoding: binary\n");
}
?>
但是当我运行此代码时,我得不到pdf文件.. 我的代码有问题吗?
答案 0 :(得分:0)
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . OCIResult($stid,'PDFFILE') . '"');
header("Content-Length: " . filesize(OCIResult($stid,'PDFFILE')->load()));
header('Content-Disposition: attachment; header("Content-Transfer-Encoding: binary\n");
您要发送Content-Disposition
标题两次。您可能甚至不需要第二个,客户端应该知道它需要知道的来自Content-Type
标头的流。省略第二个Content-Disposition
,这样你就不会覆盖具有文件名的标题。