2016-11-14 5 views
0

PHP에서 pdf를 다운로드하려고하는데 할 수 있습니까? 누구든지 나를 도울 수 있습니까?
이 코드로 시도해 보았지만 작동하지 않습니다.PHP에서 pdf를 어떻게 다운로드 할 수 있습니까?

$file ="cv0.pdf"; 
$filename = "cv0descargado.pdf"; // el nombre con el que se descargara, puede ser diferente al original 
header("Content-type: application/octet-stream"); 
header("Content-Type: application/force-download"); 
header("Content-Disposition: attachment; filename=\"$filename\"\n"); readfile($file); 
+5

가능한 중복 : // 유래를 .com/questions/364946/how-to-make-pdf-file-download-in-html-link) –

+1

"작동하지 않는다"는 것은 무엇을 의미합니까? – Chris

+1

오류를 찾으셨습니까? 또는 뭔가. – Karthi

답변

0
$file = $_GET["file"]; 
if (file_exists($file)) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header("Content-Type: application/force-download"); 
    header('Content-Disposition: attachment; filename=' . urlencode(basename($file))); 
    // header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    ob_clean(); 
    flush(); 
    readfile($file); 
    exit; 

JS으로이 방법을

+0

저자를 언급하는 것이 좋습니다. http://stackoverflow.com/a/8122372/1158599 –

+0

예 내 컴퓨터에서 검색하지만 캔트는 Google에서 검색하여 답변을 제공합니다. – Ronak

0

PHP를 사용을 시도하십시오 :

<?php $path = "yourfilepath/name.pdf"; ?> 

<button onclick="imageClick('<?php echo $path ?>')">Click</button> 

<script> 
    function imageClick(url) { 
    var a = document.createElement("a"); 
    a.target = "_blank"; 
    a.href = url; 
    a.click(); 
     } 
</script> 
[HTML 링크에서 PDF 파일 다운로드를 만드는 방법?] (HTTP의
관련 문제