donglv1831 2018-12-18 19:17
浏览 245

将音频文件上载到服务器端页面的问题

I'm having a problem to upload the audio file to the server side page. Here are the codes. I can record and download the files but the issue is that I cant upload the following files to the upload.php. I'm currently using xampp. Can anyone help me please? Javascript:

var upload = document.createElement('a');
upload.href="#";
upload.innerHTML = "Upload";
upload.addEventListener("click", function(event){
      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("audio_data",blob, filename);
      xhr.open("POST","upload.php",true);
      xhr.send(fd);
});
li.appendChild(document.createTextNode (" "));  //add a space in between
li.appendChild(upload);  //add the upload link to li

//add the li element to the ol
recordingsList.appendChild(li);

}

php:

    <?php
print_r($_FILES); //this will print out the received name, temp name, type, size, etc.
$size = $_FILES['audio_data']['size']; //the size in bytes
$input = $_FILES['audio_data']['tmp_name']; //temporary name that PHP gave to the uploaded file
$output = $_FILES['audio_data']['name'].".wav"; //letting the client control the filename is a rather bad idea
//move the file from temp name to local folder using $output name
move_uploaded_file($input, $output)
?>

html:

    <div id="controls">
 <button id="recordButton">Record</button>
 <button id="pauseButton" disabled>Pause</button>
 <button id="stopButton" disabled>Stop</button>
</div>
<div id="formats">Start</div>
<h3>Recordings</h3>
<ol id="recordingsList"></ol>
  • 写回答

1条回答 默认 最新

  • doutangdan3588 2018-12-18 19:33
    关注

    When pressing the pload button the following errors occurs: enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败