2

I am using recorder.js. My goal is to upload recording to server, it seems like the audio blob is being posted to the server. But I keep getting null returned for $_FILES["file"]["tmp_name"];

Javascript:

function uploadAudio(){
audioRecorder.stop();
audioRecorder.exportWAV(function(audio) {
var fd = new FormData();
fd.append('filename', 'test.wav');
fd.append('data', blob);
$.ajax({
    type: 'POST',
    url: 'testthing.php',
    data: fd,
    processData: false,
    contentType: false
}).done(function(data) {
       console.log(data);
});
});
}

PHP:

$res="recordings/";
$yo = $_FILES["file"]["tmp_name"];
rename($yo,$res.'test.wav');

this is what I get for header data posted using firebug in firefox:

-----------------------------2600221228510
Content-Disposition: form-data; name="filename"

test.wav
-----------------------------2600221228510
Content-Disposition: form-data; name="data"; filename="blob"
Content-Type: audio/wav
Jeff
  • 1,018
  • 1
  • 15
  • 33

1 Answers1

3

Thanks to Pass Blob through ajax to generate a file I was able to get it to work

javascript:

audioRecorder.exportWAV(function(blob) {

      var url = (window.URL || window.webkitURL).createObjectURL(blob);
      console.log(url);

      var filename = "test.wav";
      var data = new FormData();
      data.append('file', blob);

      $.ajax({
        url :  "testthing.php",
        type: 'POST',
        data: data,
        contentType: false,
        processData: false,
        success: function(data) {
          alert("boa!");
        },    
        error: function() {
          alert("not so boa!");
        }
      });
}); 

php:

if(isset($_FILES['file']) and !$_FILES['file']['error']){
    $fname = "11" . ".wav";

    move_uploaded_file($_FILES['file']['tmp_name'], "recordings/" . $fname);
}
?>
Community
  • 1
  • 1
Jeff
  • 1,018
  • 1
  • 15
  • 33