base64 处理图片

admin2年前Laravel840

public function images()
{
   $image = request()->input('image');

   if (empty($image)) {
       return $this->error('图片为空');
   }
   try {
       //base64 处理
       if (strstr($image, ",")) {
           $image = explode(',', $image);
           $image = $image[1];
       }
       $imageName = "p_" . date("His", time()) . "_" . rand(1111, 9999) . '.jpg';
       $path = "upload/image/" . date("Ymd");
       if (!is_dir($path)) { //判断目录是否存在 不存在就创建
           mkdir($path, 0777, true);
           chmod($path, 0777);
       }
       $imageSrc = $path . "/" . $imageName; //图片名字
       $r = file_put_contents($imageSrc, base64_decode($image));//返回的是字节数
       $url = $this->doamin() . '/' . $imageSrc;
       return $this->success('成功', $url);
   } catch (Exception $e) {
       return $this->error("上传失败" . $e->getMessage());
   }
}

返回列表

上一篇:批量处理数据

下一篇:忘记密码

相关文章

过滤违禁词

/** * 内容验证 */public function check($content){    $count = 0; //违规词的个数    $list =...

编辑用户信息

*/public function useredit(){    $avatar = request()->input('avatar');   &...

关注公众号并登录

/* * 服务端生成带唯一标识二维码并将唯一标识返回给前端 */ public function wx_code() { $scene_str = $this->get_...

压缩图片

public static function size($id, $img) { try { list($width, $height, $img_type, $attr) = @getimages...

设置项目编号

$max = Db::table('member')->max('id') ?? 0; if ($max < 100000) { $cd = $this->create...

获取微信的Token

 public function Token()    {        $this->path = __DIR__ . &...