2011-03-04 12 views
0

안녕하세요 PHP MVC 프레임 워크를 개발 중입니다. 사용자에게 몇 가지 파일을 제공해야하며 다운로드 링크를 어떻게 작성해야할지 모르겠습니다. 문서의 주소에 하이퍼 링크를 만들려고했지만 제대로 작동하지 않는 것 같습니다. 어떤 문서는 이상적 일 것입니다.강제로 PHP에서 파일 다운로드

답변

4
$fullpath = $_SERVER['DOCUMENT_ROOT']."/foldername/document.pdf"; //Full path of document 
$filename = "document.pdf"; //Document file nmae 


    $mm_type="application/octet-stream"; 

    header("Cache-Control: public, must-revalidate"); 
    header("Pragma: hack"); 
    header("Content-Type: " . $mm_type); 
    header("Content-Length: " .(string)(filesize($fullpath))); 
    header('Content-Disposition: attachment; filename="'.$filename.'"'); 
    header("Content-Transfer-Encoding: binary\n"); 
관련 문제