客户端JavaScript函数上传WAV blob:
function upload(blob) {
var xhr=new XMLHttpRequest();
xhr.οnlοad=function(e) {
if(this.readyState === 4) {
console.log("Server returned: ",e.target.responseText);
}
};
var fd=new FormData();
fd.append("that_random_filename.wav",blob);
xhr.open("POST","",true);
xhr.send(fd);
}
PHP文件upload_wav.php:
// get the temporary name that PHP gave to the uploaded file
$tmp_filename=$_FILES["that_random_filename.wav"]["tmp_name"];
// rename the temporary file (because PHP deletes the file as soon as it's done with it)
rename($tmp_filename,"/tmp/uploaded_audio.wav");
?>
之后你可以播放文件/tmp/uploaded_audio.wav.
但要记住! /tmp/uploaded_audio.wav是由用户www-data创建的,并且(默认情况下为PHP)用户无法读取.要自动添加适当的权限,请附加该行
chmod("/tmp/uploaded_audio.wav",0755);
到PHP的末尾(在PHP结束标记之前?>).
希望这可以帮助.