junyi-bk
    public function base64(){
        //接收base64数据
        $image= $_POST[\'imegse\'];
        //设置图片名称
        $imageName = "25220_".date("His",time())."_".rand(1111,9999).\'.png\';
        //判断是否有逗号 如果有就截取后半部分
        if (strstr($image,",")){
            $image = explode(\',\',$image);
            $image = $image[1];
        }
        //设置图片保存路径
        $path = "./".date("Ymd",time());

        //判断目录是否存在 不存在就创建
        if (!is_dir($path)){
            mkdir($path,0777,true);
        }

        //图片路径
        $imageSrc= $path."/". $imageName;

        //生成文件夹和图片
        $r = file_put_contents($imageSrc, base64_decode($image));
        if (!$r) {
            return json([\'code\'=>0,\'message\'=>\'图片生成失败\']);
        }else {
            return json([\'code\'=>1,\'message\'=>\'图片生成成功\']);
        }
}

 

分类:

技术点:

相关文章:

  • 2021-12-03
  • 2021-11-19
  • 2021-11-14
  • 2021-11-07
  • 2021-05-02
  • 2021-12-17
  • 2021-12-15
  • 2021-11-13
猜你喜欢
  • 2021-11-07
  • 2021-12-05
  • 2022-01-14
  • 2021-11-01
  • 2021-11-21
  • 2021-12-21
  • 2021-08-02
相关资源
相似解决方案