我转换Base64字符串在php到mp3声音文件,但产生的文件wav损坏
在转换音调之前声音沙沙作响
例如,语音文件可以转换为:
http://vocaroo.com/i/s1Dlol5Wu3Zo
php代码:
<?php
if(isset($_POST['audio'])){
$data = str_replace('data:audio/wav;base64,', '', $_POST['audio']);
$data = base64_decode($data);
$track_name = get_random_string(mt_rand(6,10)) . ".mp3";
$upl_dir = "../up/" . $track_name;
if( !file_put_contents($upl_dir, $data) ){
$response['status'] = 1;
$response['message'] = "File could not be uploaded. Try again >later.";
echo $data;
echo "E1";
}
echo $data;
}
我在转换之前测试了声音,结果是对的。
Base64代码:
js代码base64创建者:
function base641()
{
Fr.voice.export(function(url){
// console.log("Here is the base64 URL : " + url);
base = url;
ejem2 = 1;
// alert("Check the web console for the URL");
// $("<a href='"+ url +"' target='_blank'></a>")[0].click();
}, "base64");
};
发布于 2017-01-15 00:02:03
试试这个:
file_put_contents('audio.mp3', base64_decode($data));
https://stackoverflow.com/questions/41651980
复制相似问题