2011-01-24 5 views
1

젠드 프레임 워크에서 응용 프로그램을 개발했습니다./project/data/uploads 또는/projects/application/data/uploads와 같은 공용 폴더 외부에 특정 보안 이미지 및 pdf 문서를 저장하려고합니다.젠드 프레임 워크에서 공개 폴더 외부의 이미지 또는 문서에 액세스

공용 폴더 이외의 이미지/pdf 문서에 액세스 할 수 없습니다. 누군가 그것을 할 수있는 방법을 제안 할 수 있습니까?

당신은 가져오고 모든 물건을 전달하는 방법을 알고있는 별도의 조치를 가져야

+0

업로드 폴더의 권한을 올바르게 설정 했습니까? – Marcin

답변

2

감사합니다. 이런 식으로 뭔가가 :

물론
public function viewpdfAction() 
{ 
    $id = (int) $this->_getParam('id', 0); 

    // You implement some function - either here in your controller 
    // or someplace else - to get the pdf name from the passed id. 
    // Alternatively, you can pass the name itself. Up to you, of course. 
    // The key is that the request somehow identifies the file requested. 
    $pdfName = $this->_mapPdfIdToName($id); 

    // The path to the real pdf 
    $pdfFile = '/project/data/uploads/pdf/' . $pdfName; 

    // Disable rendering 
    $this->_helper->viewRenderer->setNoRender(true); 

    // Send the right mime headers for the content type 
    $this->getResponse() 
     ->setBody('') 
     ->setHeader('Cache-control', 'public') // needed for IE, I have read 
     ->setHeader('Content-type', 'application/pdf') 
     ->setHeader('Content-Disposition', sprintf('attachment; filename="%s"', $pdfName)); 

    // Send the content 
    readfile($pdfFile); 
} 

,이 중 일부는 가능한 한 얇은 컨트롤러를 유지하기 위해 서비스 클래스로 푸시 다운 할 수 있습니다. 이 점에서 모든 사람들은 서로 다른 취향을 가지고 있습니다.

나는이 코드가 완전히 테스트되지 않았다고 고백하며, 대부분 기본 아이디어를 제공하려고합니다. 여기에 총 뼈대 오류가 발생하면 알려주십시오.

희망이 있습니다.

관련 문제