2013-08-05 3 views
1

오디오 비디오 및 pdf 파일 php header() 함수를 사용하고 있지만 출력 파일을 다운로드하는 대신 파일을 다운로드하는 대신 PHP 페이지를 다운로드합니다. 여기 내 코드가있다.파일을 다운로드하는 방법

header('Content-disposition: attachment; 
      Content-type: audio/mpeg; 
      filename=thefile.type'); 
+1

봐 작동 : http://stackoverflow.com/questions/5595485/php-file-download?rq=1 – Pitchinnate

+0

은 왜 그냥 연결하거나 리디렉션 해달라고 파일? 'header ("location : thefile.type"); ' – user20232359723568423357842364

+0

@Pitchinnate 감사합니다. –

답변

0

파일의 내용을 밖으로 작성해야합니다.

header('Content-disposition: attachment; 
    Content-type: audio/mpeg; 
    filename=thefile.type'); 
echo file_get_contents("thefile.type"); 
+0

'echo file_get_contents ...'! – Cooper

+0

와우. 잊어 버렸습니다. 고마워. –

0

이 여기에 꽤 잘

if (file_exists("audio/thefile.type")) 
    { 
     if (FALSE!== ($handler = fopen('thefile.type', 'r'))) 
      { 
      header('Content-Description: File Transfer'); 
      header('Content-Type: application/octet-stream'); 
      header('Content-Disposition: attachment; 
        filename=audio/thefile.type'); 
      header('Content-Transfer-Encoding: chunked'); //changed to chunked 
      header('Expires: 0'); 
      header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
      header('Pragma: public'); 
      //header('Content-Length: ' . filesize('thefile.type')); //Remove 

      //Send the content in chunks 
      while(false !== ($chunk = fread($handler,4096))) 
        { 
        echo $chunk; 
        } 
      } 
      exit; 
    } 
    else{ 

      echo "<h1>Content error</h1><p>The file does not exist!</p>"; 
     } 
관련 문제