a.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. public function new_image($param)
  2. {
  3. $check_res = $this->checkImg();
  4. if ($check_res[ "code" ] >= 0) {
  5. $file = request()->file($param[ "name" ]);
  6. if (empty($file))
  7. return $this->error();
  8. $tmp_name = $file->getPathname();//获取上传缓存文件
  9. $original_name = $file->getOriginalName();//文件原名
  10. // $file_path = $this->upload_path."/".$this->site_id . "/images/".date("Ymd"). '/';
  11. $file_path = $this->path;
  12. // 检测目录
  13. $checkpath_result = $this->checkPath($file_path);//验证写入文件的权限
  14. if ($checkpath_result[ "code" ] < 0)
  15. return $checkpath_result;
  16. $file_name = $file_path . $this->createNewFileName();
  17. $extend_name = $file->getOriginalExtension();
  18. $thumb_type = $param[ "thumb_type" ];
  19. //原图保存
  20. $new_file = $file_name . "." . $extend_name;
  21. $image = Image::make($tmp_name);
  22. $width = $image->width();//图片宽
  23. $height = $image->height();//图片高
  24. $image = $this->imageWater($image);
  25. move_uploaded_file($tmp_name,$_SERVER['DOCUMENT_ROOT'].'/'.$new_file);
  26. $put_result = event("Put", [ "file_path" => $new_file, "key" => $new_file ], true);
  27. if (!empty($put_result)) {
  28. $this->deleteFile($new_file);
  29. if ($put_result[ "code" ] >= 0) {
  30. $info = $put_result[ "data" ][ "path" ];
  31. } else {
  32. return $put_result;
  33. }
  34. }
  35. //云上传没有成功 保存到本地
  36. return $this->success(['pic_path'=>$info], "UPLOAD_SUCCESS");
  37. } else {
  38. //返回错误信息
  39. return $check_res;
  40. }
  41. }