2010-01-19 7 views
0

원래 우편 번호를 다운로드하면 제대로 작동하지만 아래의 헤더를 사용하여 다운로드하면 작동하지 않습니다. 이 경로를 사용하고 브라우저에 파일을 처리하는 방법보다는 브라우저에 파일을 처리하는 방법을 알려주는 것이 좋지만이 방법을 사용할 수는 없으므로 머리글()을 사용하려고합니다.파일 다운로드가 작동하지 않습니다.

  $path = $this->tru->config->get('root.path').'/Digital Version of Book for Web.zip'; 

      set_time_limit(0); 
      header("Cache-Control: public"); 
      header("Content-Description: File Transfer"); 
      header('Content-Type: application/zip'); 
      header("Content-Transfer-Encoding: binary"); 
      header('Content-Disposition: attachment; filename="NewFileName.zip"'); 
      header('Content-Length: ' . filesize($path)); 

      $f = fopen($path, 'rb'); 
      fpassthru($f); 
      fclose($f); 

편집 :

죄송합니다, 제가 그것에 의해 의미 작동하지 않는 것은 zip 형식의 파일 다운로드 (모두 9.3 MB가)하지만 난 때문에 압축을 풀어야 드릴 수 없습니다 것입니다 그것은 유효하지 않습니다.

+0

"작동하지 않는다"는 것은 너무 애매합니다. 무엇이 잘못되었는지 설명해주십시오. 파일이 손상 되었습니까? –

+0

이것 좀보세요 : http://stackoverflow.com/questions/2088267/download-of-zip-file-runs-a-corrupted-file-php/2088331#2088331 – Gumbo

답변

1

메모장이나 다른 텍스트 편집기를 사용하여 ZIP 파일을 살펴보십시오. 처음 몇 줄에 파일 오류가 있는지 PHP 오류 메시지가 있는지 확인하십시오. 스크립트가 안전 모드에 있기 때문에 "헤더가 이미 전송되었습니다"라는 메시지 또는 set_time_limit() 호출이 오류를 발생시킬 수 있습니다.

0

readfile()을 사용해보세요. 예가 PHP Manual에 제공됩니다.

$file = 'monkey.gif'; 

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

동일한 예제를 사용하고 있지만 내 로컬 호스트에서 작동하지 않습니다. 나는'$ file = "../ files/myfile.pptx"'를 가졌다. 이 문제가 있습니까? –

관련 문제