|
@@ -551,18 +551,27 @@ class TemplateController extends Controller
|
551
|
551
|
}
|
552
|
552
|
|
553
|
553
|
public function uploadBack(Request $request){
|
554
|
|
- $img =
|
555
|
|
- $img = str_replace('data:image/png;base64,', '', $img);
|
556
|
|
- $img = str_replace(' ', '+', $img);
|
557
|
|
- $file = base64_decode($img);
|
558
|
|
-
|
559
|
|
- $ossClient=new oss();
|
560
|
|
- // 上传阿里云
|
561
|
|
- $file = $ossClient->upload($file->getClientOriginalExtension(), $file->getRealPath(), 'upload/seafoodPic'.date("Y-m-d",time()).'/'.date('His'));
|
562
|
|
- $img=$file['oss-request-url'];
|
563
|
|
- $back_img=str_replace("kx-youhuiquan.oss-cn-beijing.aliyuncs.com","imgs.726p.com",$img);
|
564
|
|
- #保存背景图
|
565
|
|
- TemplatesBackimg::insert(['back_img'=>$back_img]);
|
|
554
|
+ $img = $request->input('img');
|
|
555
|
+ if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img, $res)) {
|
|
556
|
+ //获取图片类型
|
|
557
|
+ $type = $res[2];
|
|
558
|
+ //图片名字
|
|
559
|
+ $fileName = md5(time()) . '.' . $type;
|
|
560
|
+ // 临时文件
|
|
561
|
+ $tmpfname = tempnam("/image/", "FOO");
|
|
562
|
+ //保存图片
|
|
563
|
+ $handle = fopen($tmpfname, "w");
|
|
564
|
+ //阿里云oss上传的文件目录
|
|
565
|
+ if (fwrite($handle, base64_decode(str_replace($res[1], '', $imgBase64))))
|
|
566
|
+ {
|
|
567
|
+ $ossClient=new oss();
|
|
568
|
+ // 上传阿里云
|
|
569
|
+ $file = $ossClient->upload($file->getClientOriginalExtension(), $file->getRealPath(), 'upload/seafoodPic'.date("Y-m-d",time()).'/'.date('His'));
|
|
570
|
+ $img=$file['oss-request-url'];
|
|
571
|
+ $back_img=str_replace("kx-youhuiquan.oss-cn-beijing.aliyuncs.com","imgs.726p.com",$img);
|
|
572
|
+ #保存背景图
|
|
573
|
+ TemplatesBackimg::insert(['back_img'=>$back_img]);
|
|
574
|
+ }
|
566
|
575
|
}
|
567
|
576
|
|
568
|
577
|
|