您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将Chrome中记录的WAV文件保存到服务器

将Chrome中记录的WAV文件保存到服务器

客户端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标签之前?>)。

希望这可以帮助。

其他 2022/1/1 18:16:16 有575人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶