[SOLVED] Outputting wav sound file through php
Posted: Sat May 28, 2005 6:02 pm
Hi,
I'm trying to output a .wav file through php. I want to embed the wave file on a page without showing the URL to the file. So I have the embed src as a php file. The php file that I am trying to use to get the wave file and send it to the browser to play contains the following code:
I have tried many different things and this was my last attempt at it. I got most of this code from a comment on php.net. This hasn't seemed to have worked. Can anyone please help. All it outputs to the browser is funny code.
-Kyle
I'm trying to output a .wav file through php. I want to embed the wave file on a page without showing the URL to the file. So I have the embed src as a php file. The php file that I am trying to use to get the wave file and send it to the browser to play contains the following code:
Code: Select all
<?php
$digit = $_GETї'd'] - 1;
/* initialize a session. */
session_start();
$code = $_SESSIONї'ver_code'];
$sound = $code{$digit};
$file_name = $sound . "e;.wav"e;;
/*/
Download a file using fpassthru()
/*/
$fullpath = '/home/rowgoco/public_html/anti-spam/sounds/' . $file_name;
$ext = 'wav';
function mimeTypes($file) {
if (!is_file($file) || !is_readable($file)) return false;
$types = array();
$fp = fopen($file,"e;r"e;);
while (false != ($line = fgets($fp,4096))) {
if (!preg_match("e;/^\s*(?!#)\s*(\S+)\s+(?=\S)(.+)/"e;,$line,$match)) continue;
$tmp = preg_split("e;/\s/"e;,trim($matchї2]));
foreach($tmp as $type) $typesїstrtolower($type)] = $matchї1];
}
fclose ($fp);
return $types;
}
# ї...]
# read the mime-types
$mimes = mimeTypes('/usr/local/apache/current/conf/mime.types');
# use them ($ext is the extension of your file)
if (isset($mimesї$ext])) header("e;Content-Type: "e;.$mimesї$ext]);
header("e;Content-Length: "e;.@filesize($fullpath));
readfile($fullpath); exit;
?>-Kyle