当我用PHP下载服务器上的wav音乐文件时,wav文件能够下载下来,并且大小相同,但是却不能播放。但若是通过文件服务器拷贝到本地,是可以播放该文件的,不知道如何原因。通过MD5sum检测,该文件下载后已改变,不知道在哪里被修改,请教大家,谢谢!<?php
include ("./lib/defines.php");
include ("./lib/functions.php");
include ("./lib/database.php");session_start();getpost_ifset(array('confno', 'bookid'));$query = "SELECT confOwner from " . DB_TABLESCHED . " WHERE bookid=?";
$data = array($bookid);$result = $db->query($query, $data);
$row = $result->fetchRow();
if ($_SESSION['auth'] && ($_SESSION['privilege'] == "Admin" ||
    $row[0] == $_SESSION['userid'])) {
        if (is_numeric($confno) && is_numeric($bookid)) {
                $file = "meetme-conf-rec-".$confno . "-" . $bookid . ".wav";
                $playfile = "/var/lib/asterisk/sounds/" . $file ;
                $mimetype = "audio/x-wav";
                $content_len = filesize($playfile);
                header("Content-Type:".$mimetype);
                header("Content-Transfer-Encoding:binary");
                header("Content-Length:".$content_len);
                header("Cache-Control:private");
                header('Content-Disposition: attachment; filename="'.$file.'"');
                readfile($playfile);
        }
}
?>

解决方案 »

  1.   

    Hi, 
    this is my download php script.
    it's functional for u.
    <?php
      $file = "C:\\Windows\\Media\\tada.wav";  /**
       * downloadFile  
       * @paramemter String $file : fullpath required
       */ 
      function downloadFile($file) {
          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;
          } else {
          echo "Download file: [$file] is  not found\n";
      }
      }
      # main
      downloadFile($file);
    ?>