Link to home
Start Free TrialLog in
Avatar of damijim
damijimFlag for United States of America

asked on

PHP Header Function Attempt to Play WAV in Browser

Hello,
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");
fpassthru($fh);
fclose($fh);
unlink("tmp/" . $random_string . ".wav");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JoachimMartinsen
JoachimMartinsen
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of damijim

ASKER

Thanks, what happens if they don't have an audio player in their browser? Will it then ask to download?
Yes, thats correct.
Avatar of damijim

ASKER

Thank you!