正在显示
5 个修改的文件
包含
28 行增加
和
10 行删除
| @@ -158,7 +158,7 @@ class BaseController extends Controller | @@ -158,7 +158,7 @@ class BaseController extends Controller | ||
| 158 | } | 158 | } |
| 159 | switch ((string) $k) { | 159 | switch ((string) $k) { |
| 160 | case 'image': | 160 | case 'image': |
| 161 | - $v['image_link'] = file_get_contents($v); | 161 | + $v['image_link'] = url('/image/' . $v); |
| 162 | break; | 162 | break; |
| 163 | } | 163 | } |
| 164 | } | 164 | } |
| @@ -87,10 +87,8 @@ class ImageController | @@ -87,10 +87,8 @@ class ImageController | ||
| 87 | public function upload() { | 87 | public function upload() { |
| 88 | $this->request->validate([ | 88 | $this->request->validate([ |
| 89 | 'image'=>['required'], | 89 | 'image'=>['required'], |
| 90 | - 'type'=>['required'], | ||
| 91 | ],[ | 90 | ],[ |
| 92 | 'image.required'=>'图片必须填写', | 91 | 'image.required'=>'图片必须填写', |
| 93 | - 'type.required'=>'类型必须填写', | ||
| 94 | ]); | 92 | ]); |
| 95 | $files = $this->request->file('image'); | 93 | $files = $this->request->file('image'); |
| 96 | if (empty($files)) { | 94 | if (empty($files)) { |
| @@ -123,11 +121,12 @@ class ImageController | @@ -123,11 +121,12 @@ class ImageController | ||
| 123 | 'path' => $url.$filename, | 121 | 'path' => $url.$filename, |
| 124 | 'created_at' => date('Y-m-d H:i:s',time()), | 122 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 125 | 'size' => $res->getSize(), | 123 | 'size' => $res->getSize(), |
| 126 | - 'hash' => sha1($url.$filename.date('Y-m-d H:i:s',time())), | 124 | + 'hash' => $files->hashName(), |
| 125 | + 'mime'=>$files->extension() | ||
| 127 | ]; | 126 | ]; |
| 128 | $imageModel = new ImageModel(); | 127 | $imageModel = new ImageModel(); |
| 129 | $imageModel->add($data); | 128 | $imageModel->add($data); |
| 130 | - return 'image/'.$data['hash']; | 129 | + return $data['hash']; |
| 131 | } | 130 | } |
| 132 | /** | 131 | /** |
| 133 | * 生成缩略图缓存 | 132 | * 生成缩略图缓存 |
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Logic\Bside; | 3 | namespace App\Http\Logic\Bside; |
| 4 | 4 | ||
| 5 | +use App\Enums\Common\Code; | ||
| 5 | use App\Exceptions\BsideGlobalException; | 6 | use App\Exceptions\BsideGlobalException; |
| 6 | use App\Http\Logic\Logic; | 7 | use App\Http\Logic\Logic; |
| 7 | use App\Models\Image as ImageModel; | 8 | use App\Models\Image as ImageModel; |
| @@ -101,15 +102,19 @@ class BaseLogic extends Logic | @@ -101,15 +102,19 @@ class BaseLogic extends Logic | ||
| 101 | $filename = date('ymdHis').rand(10000,99999); | 102 | $filename = date('ymdHis').rand(10000,99999); |
| 102 | $res = $request->file('image')->move($url,$filename); | 103 | $res = $request->file('image')->move($url,$filename); |
| 103 | if ($res === false) { | 104 | if ($res === false) { |
| 104 | - return $this->fail($image->getError(), 400); | 105 | + return $this->fail($image->getError(), Code::USER_ERROR); |
| 105 | } | 106 | } |
| 106 | $data = [ | 107 | $data = [ |
| 107 | 'path' => $url.$filename, | 108 | 'path' => $url.$filename, |
| 108 | 'created_at' => date('Y-m-d H:i:s',time()), | 109 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 109 | 'size' => $res->getSize(), | 110 | 'size' => $res->getSize(), |
| 110 | - 'hash' => $res->hash(), | 111 | + 'hash' => $image->hashName(), |
| 112 | + 'mime'=>$image->extension() | ||
| 111 | ]; | 113 | ]; |
| 112 | - $imageModel->add($data); | ||
| 113 | - return $data; | 114 | + $rs = $imageModel->add($data); |
| 115 | + if ($rs === false) { | ||
| 116 | + return $this->fail('添加失败', Code::USER_ERROR); | ||
| 117 | + } | ||
| 118 | + return $data['hash']; | ||
| 114 | } | 119 | } |
| 115 | } | 120 | } |
| @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside; | @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Models\User; | 6 | use App\Models\User; |
| 7 | +use Illuminate\Support\Facades\DB; | ||
| 7 | 8 | ||
| 8 | class UserLogic extends BaseLogic | 9 | class UserLogic extends BaseLogic |
| 9 | { | 10 | { |
| @@ -28,6 +29,10 @@ class UserLogic extends BaseLogic | @@ -28,6 +29,10 @@ class UserLogic extends BaseLogic | ||
| 28 | if($info !== false){ | 29 | if($info !== false){ |
| 29 | $this->fail('error',Code::USER_ERROR); | 30 | $this->fail('error',Code::USER_ERROR); |
| 30 | } | 31 | } |
| 32 | + //上传图片 | ||
| 33 | + if(isset($this->param['image'])){ | ||
| 34 | + $this->param['image'] = $this->upload(); | ||
| 35 | + } | ||
| 31 | //密码加密 | 36 | //密码加密 |
| 32 | $this->param['password'] = base64_encode(md5($this->param['password'])); | 37 | $this->param['password'] = base64_encode(md5($this->param['password'])); |
| 33 | $rs = $this->model->add($this->param); | 38 | $rs = $this->model->add($this->param); |
| @@ -51,6 +56,15 @@ class UserLogic extends BaseLogic | @@ -51,6 +56,15 @@ class UserLogic extends BaseLogic | ||
| 51 | $this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE); | 56 | $this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE); |
| 52 | } | 57 | } |
| 53 | $this->param['operator_id'] = $this->user['id']; | 58 | $this->param['operator_id'] = $this->user['id']; |
| 59 | + //上传图片 | ||
| 60 | + if(isset($this->param['image'])){ | ||
| 61 | + //查看当前用户是否已有头像 | ||
| 62 | + $info = $this->model->read(['id'=>$this->param['id']],'hash'); | ||
| 63 | + if($info !== false){ | ||
| 64 | + DB::table('gl_image')->where(['hash'=>$info['hash']])->first(); | ||
| 65 | + } | ||
| 66 | + $this->param['image'] = $this->upload(); | ||
| 67 | + } | ||
| 54 | $rs = $this->model->edits($this->param); | 68 | $rs = $this->model->edits($this->param); |
| 55 | if($rs === false){ | 69 | if($rs === false){ |
| 56 | $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); | 70 | $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); |
| @@ -164,5 +164,5 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -164,5 +164,5 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 164 | Route::group([], function () { | 164 | Route::group([], function () { |
| 165 | Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); | 165 | Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); |
| 166 | Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); | 166 | Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); |
| 167 | - Route::get('/image/{hash}/{w}/', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show'); | 167 | + Route::get('/image/{hash}/{w}/{h}', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show'); |
| 168 | }); | 168 | }); |
-
请 注册 或 登录 后发表评论