通过 ajax 返回 NULL 发布到 PHP 的音频 blob

audio blob posted to PHP via ajax returning NULL

我正在使用 recorder.js。我的目标是将录音上传到服务器,似乎音频 blob 正在发布到服务器。但是我一直为 $_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');

这是我在 firefox 中使用 firebug 发布的 header 数据得到的结果:

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

test.wav
-----------------------------2600221228510
Content-Disposition: form-data; name="data"; filename="blob"
Content-Type: audio/wav

多亏了Pass Blob through ajax to generate a file,我才能够让它工作

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);
}
?>