base64 处理图片

admin1年前Laravel584

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 dyqrcode($uid){    $url = "https://open.douyin.com/api/apps/v1/qrcode...

发送公众号信息

* 发送消息 */public function tosend($openid, $title, $content, $time, $aid){    $tokens = $thi...

用户注册账号

public function register(){    $mobile = request()->input('mobile');   &nb...

php 优化

使用 gc_collect_cycles() 强制进行垃圾回收 PHP 的垃圾回收机制会自动释放不再使用的变量所占用的内存。然而,在某些情况下,尤其是在长时间运行的脚本(如 CLI...

按照距离远近排序

   $distance = "ACOS(SIN(( $lat * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((...

查找下级所有数据

public function bottom($mid = 3){    $members = DB::select('select id,parent_id,`level...