views:

70

answers:

1

When attempting to view a *.wav URL on our webserver, the data doesn't transfer properly.

We are using apache2 with php5.10. Among the apache rewrite rules is:

RewriteRule ^(.+)\.(wav)$ /wav.php?wav=$1.$2 [L,NC]

And the relevant code from wav.php is:

<?php
$image = getPassed("wav");
header( 'Content-Type: audio/wav');
set_include_path("/");
readfile($image, true);
exit;
?>

This is supposed to return any .wav file on the server when server.company.com/filepath is accessed via a web browser.

When attempting to listen to any *.wav file in firefox or chrome in ubuntu (haven't tested other OSes yet), the plugin errors: "Location not found." However, right-clicking and choosing "save link as" allows the user to download the .wav file.

Any thoughts?

Edit:

getPassed is a function to return variables from $_GET or $_POST

+1  A: 

I think that you need a couple more headers for this functionality to work, not 100% sure because I have never tried to stream a file.

header( 'Content-Type: audio/wav');
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: " . filesize($image) ."; "); 
header('filename="'.$image . '"; '); 

It is worth a shot to try it with those either way. You may also want to try a content-type of Content-Type: application/octet-stream;, you may also want to try "chunking" the file using readfile_chunked() (a user contributed function on php.net) and see if that possibly helps as well.

Hope it helps.

Brad F Jacobs