将base64转成图片
public static function imgBase64($image, $img_type='image/png')
{
// $base_img是图片的base64
$base_img = str_replace('data:' . $img_type . ';base64,', '', $image);
// 设置文件路径
$path = Yii::$app->basePath . '/runtime/';
if (!is_dir($path)) {
FileHelper::createDirectory($path); //传建文件夹
}
//图片命名
$output_file = Tool::getTotalMillisecond() . rand(1000, 9999) . '.' . explode('/', $img_type)[1];
//存放文件路径
$file = $path . $output_file;
//将数据流文件写入文件中
file_put_contents($file, base64_decode($base_img));
// 输出文件
return $file;
}