2012-02-04 10 views
0

웹 루트 외부에 많은 문서를 저장합니다.PHP 웹 루트 외부 파일 다운로드

링크를 클릭하여 새 창 (target = "_ blank")을 열고 강제로 찾은 파일을 다운로드하고 싶습니다. 여기

는 내가 지금까지있어 무엇, 그러나 나의 결과는 오히려 바탕 화면에 다운로드를 강제하는 대신 브라우저 팝업에서 중얼 드 노랭을 보여

function download($filelocation){ 

    $filename = basename($filelocation); 
    if (file_exists($filelocation)) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename='.$filename); 
    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($filelocation)); 
    ob_clean(); 
    flush(); 
    readfile($filelocation); 
    exit; 
    } 

} 

새 브라우저 창에서 I 단순히 파일을 특정 경로와 함께 download() 함수를 호출하십시오.

확실히 파일을 찾는 것이지만 지금은 브라우저에서 파일을 강제로 header()로 빠뜨리는 것이 궁금합니다.

+0

를 시도? – Grilse

+1

Ehm http://stackoverflow.com/questions/6724257/php-header-attach-avi-file – Vyktor

+0

브라우저에 파일 응용 프로그램 유형이 무엇인지 알려줘야 적절한 처리기를 호출 할 수 있습니다. 예를 들어 .jpg 그림 또는 .doc 파일입니까? ... Vyktor가 말한 것처럼 ... – dar7yl

답변

1

이 누락 : 어떤 브라우저는

header("Content-Type: application/force-download"); 
+0

이것을 시도해보고 같은 결과를 얻었습니다. 나는 실제 파일 형식을 반영하도록 내용 유형을 변경했습니다. – coffeemonitor