我有来自另一台服务器的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);

最佳答案

我不确定您要做什么,但是...您可能正在寻找以下内容:

//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);

关于php - PHP保存WAV文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25163454/

10-16 07:27