$base64 = 'data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD';
$url = explode(',', $base64);
$a = file_put_contents('test.png', base64_decode($url[1]));//返回的是字节数
print_r($a);die;
function save_img_by_base($base64_image_content){
    header('Content-type:text/html;charset=utf-8');
    //保存base64字符串为图片
    if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)){
        $type = $result[2];//匹配出图片的格式
        $root_path= dirname(ROOT_PATH)."/images/cardarticleimg/"; //图片保存的路径
        $path=date('Y-m-d').'/';
        $mulu=$root_path.$path;
        if(!file_exists($mulu)){
            mkdir($mulu,0777,true);
            chmod($mulu,0777);
        }
        $file_name = mt_rand().".$type";
        $new_file=$mulu.$file_name;
        /*$new_file = "./test.{$type}";*/
        if (file_put_contents("$new_file", base64_decode(str_replace($result[1], '', $base64_image_content)))){
            return $path.$file_name;
        }
    }
}