如何将base64编码的图片保存到本地并生成路径.txt文件?

2026-04-03 04:531阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计131个文字,预计阅读时间需要1分钟。

如何将base64编码的图片保存到本地并生成路径.txt文件?

将伪原创内容进行简化改写,如下:

txt将base64格式的图片保存到本地并返回路径.txtfunction save_img_by_base($base64_image_content){ header('Content-type:text/; charset=utf-8'); // 将base64字符串保存为图片 if (preg_match('/^data:image\/(\w+);base64,/', $base64_image_content, $match)) { // ... }}

如何将base64编码的图片保存到本地并生成路径.txt文件?

保存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,)/', $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; } } }

本文共计131个文字,预计阅读时间需要1分钟。

如何将base64编码的图片保存到本地并生成路径.txt文件?

将伪原创内容进行简化改写,如下:

txt将base64格式的图片保存到本地并返回路径.txtfunction save_img_by_base($base64_image_content){ header('Content-type:text/; charset=utf-8'); // 将base64字符串保存为图片 if (preg_match('/^data:image\/(\w+);base64,/', $base64_image_content, $match)) { // ... }}

如何将base64编码的图片保存到本地并生成路径.txt文件?

保存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,)/', $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; } } }