?
Solved

PHP Header Function Attempt to Play WAV in Browser

Posted on 2009-04-16
5
Medium Priority
?
1,825 Views
Last Modified: 2013-12-13
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

0
Comment
Question by:damijim
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
JoachimMartinsen earned 2000 total points
ID: 24161167
Remove line 4.
0
 
LVL 1

Author Comment

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

Expert Comment

by:JoachimMartinsen
ID: 24161279
Yes, thats correct.
0
 
LVL 1

Author Comment

by:damijim
ID: 24161297
Thank you!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

839 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