2
$path = BASE_URL."/pdf/"; 
$filename= $path.basename($_GET['download_file']);

header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; 
filename='.basename($filename));
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($filename));
readfile($filename);
exit;

此代码有效,但我Error in reading pdf file在打开下载的 pdf 时得到了。在上面的代码中,我从该位置获取文件http://localhost//eec//pdf/CV_Prabin Mishra.pdf

4

2 回答 2

1

BASE_URL最后可能有一个斜线,所以你不需要额外的:

$path = BASE_URL."pdf/"; 
于 2012-12-12T05:08:20.880 回答
1

我看不到您在哪里设置了 $filename 的值,您在 $fullPath 中设置了 PDF 的位置,然后使用 $filename 将其读出。我认为代码应该是

$path = BASE_URL."/pdf/"; 
$fullPath = $path.basename($_GET['download_file']);

header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; 
filename='.basename($fullPath));
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($fullPath));
readfile($fullPath);
exit;
于 2012-12-12T05:37:22.400 回答