2013-03-19 1 views
3

내 응용 프로그램을 WAMP 서버 (PHP 버전 < = 5.2, Windows XP)에서 LAMP 서버 (PHP 5.3, Ubuntu 12.04 LTS)로 옮겼습니다. 문제는 지금 내 다운로드 기능이 파일을 출력한다는 것입니다. 화면과 그것은 브라우저가 다운로드를 수행하도록 강요하지 않습니다.WAMP 서버에서 LAMP 서버로 변경 한 후 파일 다운로드 스크립트가 작동하지 않습니다.

누구나 올바른 방향으로 나를 가리킬 수 있습니까? 여기

코드입니다 :이다

function download() 
{ 

$fullPath = $_POST['fisier']; 

if($fullPath=="NULL") 
{ 
echo "Wrong path!"; 
} 
else 
{ 

$fd = fopen ($fullPath, "r"); 

if ($fd) { 
    $fsize = filesize($fullPath); 
    $path_parts = pathinfo($fullPath); 
    $ext = strtolower($path_parts["extension"]);  

    switch ($ext) { 
     case "pdf": 
      header("Content-type: application/pdf"); 
      break; 

     case "tiff": 
      header("Content-type: image/tiff"); 

      break; 

     case "tif": 
      header("Content-type: image/tiff"); 
      break; 

     default:  
      header("Content-type: application/force-download"); 
      break; 
    } 
    header("Content-Description: File Transfer"); 
    header('Content-Disposition: attachment; filename="'.$path_parts["basename"].'"'); 
    header("Content-length: ".$fsize); 
    header("Cache-control: private"); //use this to open files directly 


    ob_clean(); 
    flush(); 
    while(!feof($fd)) { 
     $buffer = fread($fd, 2048); 
     echo $buffer; 
    } 

} 

fclose ($fd); 
exit; 
} 
} 
+0

'헤더 ("캐시 제어 : ..).?', 파일을 열 수 없습니다 직접 또한, 당신은 왜 '사용중인 브라우저의 캐시 동작을 지정하는 데 사용됩니다 ob_clean()'마지막으로, 'file_get_contents'를 사용하여 코드를 단순화하고 파일 내용을 검색 한 다음에 에코 할 수 있습니다. – MatRt

답변

0

시도하여 header("Content-type: application/octet-stream"); 대신 header("Content-type: application/force-download");

0

"응용 프로그램/octet-stream을"엔티티를받는 구현을위한 권장 조치에 단순히 제공 데이터를 에 넣는다.

Fro m here. 너의 application/force-download이 비표준 것 같습니다.

1

당신은 당으로 Content-Disposition 헤더를 사용할 수있는 PHP docs :

당신이 원하는 경우 사용자는 전송중인 데이터, 같은 생성 된 PDF 파일로, 당신은»을 사용할 수를 저장하라는 메시지가 표시된다 Content-Disposition 헤더가 권장 파일 이름을 제공하고 브라우저에 이 저장 대화 상자를 표시하도록합니다.

// It will be called downloaded.pdf 
header('Content-Disposition: attachment; filename="downloaded.pdf"'); 
관련 문제