PHP Header Function Attempt to Play WAV in Browser

Posted on 2009-04-16
Last Modified: 2013-12-13
I have some headers that I use to send a wav file to the end-users browser. Is there a way to make it attempt to play in the wav in the user's web browser rather than the "Save/Open/Cancel" dialog box? I've attached my header code. Thanks!
//send the wav to client via headers

$size = filesize("tmp/$random_string.wav");

header("Content-Type: audio/wav", TRUE);

header("Content-Disposition: ATTACHMENT; FILENAME=\"" . $random_string . ".wav\"", TRUE);

header("Content-Length: " . $size);

header("Content-Transfer-Encoding: binary");

//open, send file, and close connection, delete (unlink) the tmp file.

$fh = fopen("tmp/$random_string.wav", "r");



unlink("tmp/" . $random_string . ".wav");

Open in new window

Question by:damijim
    LVL 6

    Accepted Solution

    Remove line 4.
    LVL 1

    Author Comment

    Thanks, what happens if they don't have an audio player in their browser? Will it then ask to download?
    LVL 6

    Expert Comment

    Yes, thats correct.
    LVL 1

    Author Comment

    Thank you!
    LVL 1

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now