js发送blob php接收,javascript如何上传blob?

我无法使用上面的示例来处理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);?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值