2017-02-07 1 views
1

다운로드하려고합니다. 이메일이 전송되지만 파일을 다운로드 할 수없는 일이 뭐죠 버튼을 파일을 제출 PDF는 다음PHP : 강제로 PDF 파일 다운로드

if(mail('[email protected]', 'Brochure Downloaded ', $string)){ 
      $text= 'Your message recieved, We will contact you shrtly '; 
      $file_url = 'http://www.website.com/brochure.pdf'; 
       header('Content-Type: application/octet-stream'); 
       header("Content-Transfer-Encoding: Binary"); 
       header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
       readfile($file_url); // do the double-download-dance (dirty but worky) 
    } 

이제 내 코드 대신 페이지를 다시로드 얻고 긴 문자가 화면에 인쇄되어

이것이 내가 헤더를 조금 변경 전 enter image description here

+0

이 아닌이 컨텐츠 길이가 필요하십니까 다른 헤더 파일을 다운로드하려면

header('Content-Length: ' . filesize($file_url)); 

당신이 콘텐츠 길이를 사용해야 사용할 수 있나요? – Eamonn

+0

내가 가진 전부는 여기 – Sikander

+0

브라우저의 검사기에서 헤더가 올바르게 설정되어 있는지 확인하십시오. 서버가이를 오버라이드 할 수 있습니다. – Eamonn

답변

0

을 얻을 것입니다이하십시오

와 당신의 도움이 필요합니다. 적절한 콘텐츠 유형이 application/pdf이고 헤더의 일부가 불필요하지 않다고 생각합니다.

if(mail('[email protected]', 'Brochure Downloaded ', $string)){ 
    $text= 'Your message recieved, We will contact you shrtly '; 
    $file_url = 'http://www.website.com/brochure.pdf'; 
    header("Content-type:application/pdf"); 
    header("Content-Disposition:attachment;filename='" . basename($file_url) . "'"); 
    readfile($file_url); // do the double-download-dance (dirty but worky) 
} 

또한 콘텐츠 길이 추가 할 수 있습니다 : 먼저 당신이 다음 헤더 이미지를 다운로드하려는 경우 등 당신이 어떤 종류의 파일을 다운로드 할 경우 콘텐츠 형식을 추가해야

header('Content-Length: ' . filesize($file_url)); 
0

확인이 코드를 ('Content-Type : image/png'); PDF의 경우 헤더 ("Content-Type : application/pdf"); 등

<?php 
if (mail('[email protected]', 'Brochure Downloaded ', $string)) { 
$text = 'Your message recieved, We will contact you shrtly '; 
$file_url = 'http://www.website.com/brochure.pdf'; 
header("Content-Description: File Transfer"); 
header("Content-Disposition: attachment; filename=$file_url"); 
header("Content-Type: application/pdf"); 
header("Content-Transfer-Encoding: binary"); 
readfile($file); 
} 
?> 

당신은 당신이 누군가가

+0

코드의 내용을 설명해야합니다. –

+0

업데이트가 있고 설명이 있습니다. –