diff --git a/app/admin/controller/v1/Images.php b/app/admin/controller/v1/Images.php index 116e22a0..a870f315 100644 --- a/app/admin/controller/v1/Images.php +++ b/app/admin/controller/v1/Images.php @@ -12,6 +12,10 @@ class Images // 上传 public function upload() { + $param = request()->param(['module']); + if (is_null($param)) { + return error('请确定请求参数正确'); + } $file = request()->file('image'); if (is_null($file)) { return error('请确定上传对象或字段是否正确'); @@ -19,9 +23,10 @@ class Images try { $validate = validate([ - 'image'=>'fileSize:1048576|fileExt:jpg,jpeg,png,gif' + 'module' => 'require|max:64', + 'image' => 'fileSize:1048576|fileExt:jpg,jpeg,png,gif' ]); - if (!$validate->check(['image' => $file])) { + if (!$validate->check(['module' => $param['module'], 'image' => $file])) { return error($validate->getError()); } @@ -44,7 +49,7 @@ class Images $image_model = new ImageModel(); } $image_model->language_id = request()->lang_id; - $image_model->image_name = $file->getOriginalName(); + $image_model->module = $param['module']; $image_model->image_path = $filename; $image_model->image_thumb = $thumb_filename; $image_model->image_size = $file->getSize(); diff --git a/app/admin/route/v1.php b/app/admin/route/v1.php index 2818846b..c35dd630 100644 --- a/app/admin/route/v1.php +++ b/app/admin/route/v1.php @@ -38,7 +38,7 @@ Route::group('v1', function () { // 图片管理 Route::group('images', function () { // 图片上传 - Route::post('upload', 'Images/upload'); + Route::post('/:module/upload', 'Images/upload'); }); // 文章模块 diff --git a/app/common/model/ImageBaseModel.php b/app/common/model/ImageBaseModel.php index b843d412..a6140a9b 100644 --- a/app/common/model/ImageBaseModel.php +++ b/app/common/model/ImageBaseModel.php @@ -20,7 +20,7 @@ class ImageBaseModel extends Model protected $schema = [ 'id' => 'int', 'language_id' => 'int', - 'image_name' => 'string', + 'module' => 'string', 'image_path' => 'string', 'image_thumb' => 'string', 'image_size' => 'int', diff --git a/database/migrations/20241220072120_create_sys_image.php b/database/migrations/20241220072120_create_sys_image.php index 536d3519..72b9c782 100644 --- a/database/migrations/20241220072120_create_sys_image.php +++ b/database/migrations/20241220072120_create_sys_image.php @@ -29,7 +29,7 @@ class CreateSysImage extends Migrator { $table = $this->table('sys_image', ['engine' => 'MyISAM', 'comment' => '图片表']); $table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID']) - ->addColumn('image_name', 'string', ['limit' => 125, 'null' => false, 'comment' => '图片名称']) + ->addColumn('module', 'string', ['limit' => 64, 'null' => false, 'comment' => '图片所属模块']) ->addColumn('image_path', 'string', ['limit' => 125, 'null' => false, 'comment' => '图片路径']) ->addColumn('image_thumb', 'string', ['limit' => 125, 'null' => false, 'comment' => '缩略图路径']) ->addColumn('image_size', 'integer', ['null' => false, 'comment' => '图片大小'])