2012-12-12 21 views
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; 

이 코드는 작동하지만 다운로드 한 PDF 파일을 열면 Error in reading pdf file이 나옵니다. 위의 코드에서 나는, 당신은 필요가 없습니다 여분의 하나 http://localhost//eec//pdf/CV_Prabin Mishra.pdfpdf의 파일 코드를 PHP로 다운로드

답변

1

BASE_URL 아마 마지막에 슬래시가있는 위치에서 파일을 가져 :

$path = BASE_URL."pdf/"; 
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;