php base64字符串转二进制流

 

function base64_to_blob($base64Str){
    if($index = strpos($base64Str,'base64,',0)){
        $blobStr = substr($base64Str,$index+7);
        $typestr = substr($base64Str,0,$index);
        preg_match("/^data:(.*);$/",$typestr,$arr);
        return ['blob'=>base64_decode($blobStr),'type'=>$arr[1]];
    }
    return false;
}

$data = base64_to_blob($base64Str);
header('Location: '.$data['type']);
echo $data['blob'];

 

posted @ 2017-03-24 15:14  Ricky_boke  阅读(6577)  评论(0编辑  收藏  举报