2009-08-25 2 views
29

을 설정하는 방법을, 어떻게 이런 일을 할 수젠드 프레임 워크는 헤더에게 내가 질문이

 $this->getResponse() 
     ->setHeader('Content-Disposition:inline', ' filename=result.pdf') 
     ->setHeader('Content-type', 'application/x-pdf'); 

을하지만 제대로 작동하지 않습니다 .

최고 감사합니다,

+0

헤더가 이미 전송 되었나요? – Pawka

+0

올바른 MIME 형식은 application/pdf입니다. –

답변

53

귀하의 문을 해결 약간 잘못되었습니다 :

$this->getResponse() 
    ->setHeader('Content-Disposition', 'inline; filename=result.pdf') 
    ->setHeader('Content-type', 'application/x-pdf'); 

위의 작동합니다 - Content-Disposition의 차이에 유의하십시오 - 머리글.

다만 ... 브라우저에서 문서를로드하는 대신 다운로드 상자를 강제로 실행하려면 Content-Dispositionattachment을 사용해야합니다.

$this->getResponse() 
    ->setHeader('Content-Disposition', 'attachment; filename=result.pdf') 
    ->setHeader('Content-type', 'application/x-pdf'); 

브라우저에 따라, 당신은 또한 application/force-download, application/octet-stream 및/또는 application/download 중 하나 이상 (다중 헤더)를 Content-Length을 설정 또는 이들의 조합에 Content-type을 변경해야 할 가능성이있을 수 있습니다. 그리고이 주석에서 썼 듯이 캐싱 헤더가 다운로드를 방해 할 수 있습니다. 전송 된 캐싱 헤더를 확인하십시오.

+0

예제가 작동하지 않습니다. SR, 다운로드 상자가 더 이상 표시되지 않습니다. 내 코드는 다음과 같습니다. http://pastebin.com/d6be142ab – Uffo

+0

어떤 브라우저를 사용합니까? 실제로 어떤 헤더가 유선을 통해 전송되는지 확인할 수 있습니까? 특히 일부 캐싱 헤더는 파일 다운로드를 방해 할 수 있습니다. –

+4

@ Uffo : 강제로 다운로드하려면 원하는 질문을 말해야합니다. 헤더를 설정하는 올바른 방법은 무엇인지 물어 보았습니다. S. Gehrig의 최초 답변은 바로 그 것입니다. – Rytmis

-5

응답 헤더를 설정하는

 $this->getResponse() 
     ->setHeader('Content-Disposition:inline', ';filename=result.pdf') 
      ->setHeader('Content-Type', 'application/x-pdf'); 
+2

S. Gehrig의 대답을 살펴보십시오. 올바른 답변입니다. 너는 일할 수도 있지만 우연히 만. ": inline"은 헤더의 일부가 아닙니다. – Rytmis

6

테이블 끝 부분에 파일을 전송하거나 메모리 데이터를 브라우저에 간단하게 재사용 할 수있는 구성 요소로 this action helper을 권장 할 수 있습니다.

캐싱, 처분에 대한 옵션을 가지고 있으며, 내 생각 엔 당신이 뭔가하고있는 것입니다 아파치 sendfile을

+0

좋은 찾기 감사합니다. – Mark

+3

링크가 죽었습니다. 어떤 대안? –

+1

@Aron http://github.com/noginn/noginn/blob/master/Noginn/Controller/Action/Helper/SendFile.php를 참조하십시오. –

2

을 이용할 수있다 :

$this->getResponse() 
     ->setHeader('Content-Disposition:inline', ' filename=result.pdf') 
     ->setHeader('Content-type', 'application/x-pdf'); 
fpassthru($filename); 
exit(); 

또는 무언가를.

여기서 응답이 렌더링되지 않습니다 (헤더를 렌더링 함). 응답은 사후 조치 인쇄 중에 렌더링됩니다.

헤더를 직접 설정해야하며 (비 Oo 코드에 명시된대로) 직접 $this->getResponse()->sendHeaders()을 사용해야합니다.

0

헤더 세트가 있습니다. 설정되지 않았지만 추가되었습니다. 그래서 Content-Type이 text/html이고 application/pdf가 있습니다.

->setHeader('Content-type', 'application/x-pdf', true);

setHeader($name, $value, $replace = false)

에서 : https://framework.zend.com/manual/1.12/de/zend.controller.response.html TRUE로 콘텐츠 형식에 플래그

에만 비밀 기호를 다운로드 또는 오류가 발생한 후 보여 IOS 및 기타 장치에서 가능한 다운로드를 만든