MP3无法在IE中播放(通过PHP输出)

时间:2014-07-01 00:42:18

标签: php html internet-explorer mp3

我只是想在网站上播放音频文件而且我编写了一个脚本来检索mp3文件而不显示URL。到目前为止,我的PHP脚本在Fire Fox,Chrome中运行良好,但在IE中却没有。每当我尝试直接从文件控制器播放音频时IE当然会询问我是否要下载mp3而不是播放它。

我的版本: PHP5 IE 9

这是我在NUTSHELL中的脚本

    require_once("wp-load.php");
    session_start();

    $documentRoot = $_SERVER['DOCUMENT_ROOT'];

    if (__FILE__ == $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'] && !isset($_GET['sign']))
    {
      die("Direct access forbidden!");
    }

     //Is user logged in?
    if(!is_user_logged_in())
    {
        echo "503 Service Unavailable";
        header('HTTP/1.1 503 Service Unavailable', true, 503);
        exit;
    }
        $current_user = wp_get_current_user();
        $user_id = $current_user->ID;

    $pathParts = pathinfo($filename);
    $mime = array(
     'jpe'  => 'image/jpeg',
     'jpeg' => 'image/jpeg',
     'jpg'  => 'image/jpeg',
     'png'  => 'image/png',
     'mp4'  => 'video/mp4',
     'mp3'  => 'audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3',
     'xls'  => 'application/vnd.ms-excel',
     'pdf'  => 'application/pdf',
     );


    //Ensure file exists
    if(!is_file($filename))
    {
        echo "404 Not Available";
        header('HTTP/1.1 404 Not Available', true, 404);

        exit;
    }

//Are we in IE?
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
    {
        header('Content-type: application/octet-stream X-Content-Type-Options: nosniff');
        header('X-Content-Type-Options: nosniff');

        header("Content-Disposition: attachment; filename=\"$filename\"");
        header("Pragma: no-cache"); //keeps ie happy
        header("Pragma: public");
        header('X-Pad: avoid browser bug');
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    }
    else
    {
        header("Cache-Control: no-cache, must-revalidate"); 
        header('Content-type: application/octet-stream');
    }

    header('Accept-Ranges: bytes');

    header('Content-length: '.filesize($filename));

    $file = @ fopen($filename, 'rb');
    if ($file)
    {
        ob_end_clean();//required here or large files will not work
        fpassthru($file); 
        exit;
    }
    echo 'File failed to load!';

我如何显示mp3 ...

<object height="40" width="600" data="media.php?file=name"></object>

0 个答案:

没有答案