客户端Javascript函数上传WAV Blob:
function upload(blob) { var xhr=new XMLHttpRequest(); xhr.onload=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","<url>",true); xhr.send(fd);}PHP文件
upload_wav.php:
<?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 end标签之前
?>)。
希望这可以帮助。



