我无法使用上面的示例来处理blob,我想知道upload.php到底是什么。所以你走了:
(仅在Chrome 28.0.1500.95中测试过)// javascript function that uploads a blob to upload.phpfunction uploadBlob(){
// create a blob here for testing
var blob = new Blob(["i am a blob"]);
//var blob = yourAudioBlobCapturedFromWebAudioAPI;// for example
var reader = new FileReader();
// this function is triggered once a call to readAsDataURL returns
reader.onload = function(event){
var fd = new FormData();
fd.append('fname', 'test.txt');
fd.append('data', event.target.result);
$.ajax({
type: 'POST',
url: 'upload.php',
data: fd,
processData: false,
contentType: false
}).done(function(data) {
// print the output from the upload.php script
console.log(data);
});
};
// trigger the read from the reader...
reader.readAsDataURL(blob);}
upload.php的内容:// pull the raw binary data from the POST array$data = substr($_POST['data'], strpos($_POST['data'], ",") + 1);// decode it$decodedData = base64_decode($data);// print out the raw data, echo ($decodedData);$filename = "test.txt";// write the data out to the file$fp = fopen($filename, 'wb');fwrite($fp, $decodedData);fclose($fp);?>