-1

mp3、flvなどの拡張子を持つファイルをダウンロードすると、ダウンロードが開始され、バッファリングが開始されます。ファイルから拡張子を削除すると、ダウンロードされます...

その背後にある問題を教えてください...

ダウンロードするファイルは => theangelfoundation-12-5-2012-09-17-27-somebody.mp3 です。

前もって感謝します ..

4

1 に答える 1

0
 $file_types=array();

             $file_types['mp3']   ='audio/mpeg';
             $file_types['mpeg']  ='video/mpeg';
             $file_types['mpg']   ='video/mpeg';
             $file_types['pdf']   ='application/pdf';
             $file_types['pps']   ='application/vnd.ms-powerpoint';
             $file_types['ppt']   ='application/vnd.ms-powerpoint';
             $file_types['ps']    ='application/postscript';
             $file = 'you.mp3';  
             download($file,$file_types);    




function download($file_name,$file_types){

          $file = $file_name;
          $ext = end(explode('.',$file_name));
          if($ext && array_key_exists($ext,$file_types)){
          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');
             header('Pragma: public');
             header('Content-Length: ' . filesize($file));
             ob_clean();
             flush();
             readfile($file);
             exit;
             }
          }
         else {
            die("this is not a downloadable file");
             }




        }


?>
<a href="force_download.php?file=ok.txt"> download ok.txt</a>
于 2012-09-18T06:29:30.907 に答える