简体   繁体   中英

How to store or upload audio file in specific location?

I need to store recorded voices at one specific location. How to store or upload recorded file to location?

Here is my script for upload audio file & upload.php file

This is my reference link: https://blog.addpipe.com/using-recorder-js-to-capture-wav-audio-in-your-html5-web-site/

//upload link
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

upload.php

<?php
print_r($_FILES); //this will print out the received name, temp name, type, size, etc.
$size = $_FILES['audio_data']['size'];
$input = $_FILES['audio_data']['tmp_name'];
$output = $_FILES['audio_data']['name'].".wav";
move_uploaded_file($input, $output)
?>

target_dir=>where don you want to store it

  $target_dir = "uploads/";
   $target_file = $target_dir . basename($_FILES["audio_data"]["name"]);


 if (move_uploaded_file($_FILES["audio_data"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["audio_data"]["name"]). " has been 

   uploaded.";

  } else {
   echo "Sorry, there was an error uploading your file.";
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM