base64 处理图片

admin1年前Laravel529

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());
   }
}

返回列表

上一篇:批量处理数据

下一篇:忘记密码

相关文章

手机号替换

 $vv = substr_replace($vv, '****', 3, 4) ....

excel 导出

header("Content-Type: application/vnd.ms-excel; name='excel'"); header("Content-Disposition:atta...

生成二维码

public function qrcode($uid){    require_once base_path() . '/public/phpqrcode/phpqrco...

PHP 严格类型

只需在 PHP 代码文件的开头加上declare(strict_types = 1);这一行魔法代码,就能开启严格类型检查之旅。...

微信退款v3

/** * 微信 退款 操作 */ public function refund($out_trade_no, $refund_money) { $time = time();...

忘记密码

publicfunction forget(){    $phone = request()->input('phone');    $c...