PHP保存wav文件

时间:2014-08-06 14:46:14

标签: php audio

我在php中有一个来自另一台服务器的wav流(不是文件)。当我想将流保存为wav文件时。它没有播放,文件已损坏。有谁能够帮我?代码是:

$file = "/var/www/sounds/soundFile.wav";
$handle  = fopen($file, 'wb')
or die('Cannot create sound file: ' . $file);
//stream_set_write_buffer($handle, 0);
fwrite($handle, $soundResult );
fclose($handle);

1 个答案:

答案 0 :(得分:-1)

我不确定你想做什么,但是......这可能是你想要的:

//send file contents
$handle=fopen(dirname(__FILE__) . "/var/www/sounds/soundFile.wav", "rb");
header("Content-type: application/octet-stream");
header('Content-disposition: attachment; filename="test.wav"');
header("Content-transfer-encoding: binary");
header("Content-length: ".filesize(dirname(__FILE__) . "/var/www/sounds/soundFile.wav")."    ");
fpassthru($handle);
fclose($handle);