2

I all I'm attempting to play an audio file in a website and I've written a script to retrieve the mp3 file without showing the URL. So far my PHP script works fine in Fire Fox, Chrome, but not in IE. Whenever I attempt to play the audio directly from the file controller IE of course asks if I would like to download the mp3 instead of playing it.

My Versions: PHP5 IE 9

Here is my script in a 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!';

How I display the mp3...

<object height="40" width="600" data="media.php?file=name"></object>
Dave Chen
  • 10,887
  • 8
  • 39
  • 67
Ajm113
  • 320
  • 1
  • 13
  • You're going to need to specify a classid for the object. Look up `clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95` for more information. – Dave Chen Jul 01 '14 at 00:46
  • The Problem is not with your PHP code . It's with IE .You can look for a way to make IE play mp3 files instead of downloading them – user00239123 Jul 01 '14 at 04:27
  • You were right about the clsid Dave Chen! Only problem now is getting the darn player to work on all platforms without the user to require to download a plugin. <_ – Ajm113 Jul 01 '14 at 14:54

0 Answers0