保存base64格式的图片到本地并返会路径.txt 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,)/', $bas
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; } } }