refactor: 修改图片上传区分模块

This commit is contained in:
2025-01-18 17:46:35 +08:00
parent 7f58da4e24
commit ba58714f5f
4 changed files with 11 additions and 6 deletions

View File

@@ -12,6 +12,10 @@ class Images
// 上传 // 上传
public function upload() public function upload()
{ {
$param = request()->param(['module']);
if (is_null($param)) {
return error('请确定请求参数正确');
}
$file = request()->file('image'); $file = request()->file('image');
if (is_null($file)) { if (is_null($file)) {
return error('请确定上传对象或字段是否正确'); return error('请确定上传对象或字段是否正确');
@@ -19,9 +23,10 @@ class Images
try { try {
$validate = validate([ $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()); return error($validate->getError());
} }
@@ -44,7 +49,7 @@ class Images
$image_model = new ImageModel(); $image_model = new ImageModel();
} }
$image_model->language_id = request()->lang_id; $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_path = $filename;
$image_model->image_thumb = $thumb_filename; $image_model->image_thumb = $thumb_filename;
$image_model->image_size = $file->getSize(); $image_model->image_size = $file->getSize();

View File

@@ -38,7 +38,7 @@ Route::group('v1', function () {
// 图片管理 // 图片管理
Route::group('images', function () { Route::group('images', function () {
// 图片上传 // 图片上传
Route::post('upload', 'Images/upload'); Route::post('/:module/upload', 'Images/upload');
}); });
// 文章模块 // 文章模块

View File

@@ -20,7 +20,7 @@ class ImageBaseModel extends Model
protected $schema = [ protected $schema = [
'id' => 'int', 'id' => 'int',
'language_id' => 'int', 'language_id' => 'int',
'image_name' => 'string', 'module' => 'string',
'image_path' => 'string', 'image_path' => 'string',
'image_thumb' => 'string', 'image_thumb' => 'string',
'image_size' => 'int', 'image_size' => 'int',

View File

@@ -29,7 +29,7 @@ class CreateSysImage extends Migrator
{ {
$table = $this->table('sys_image', ['engine' => 'MyISAM', 'comment' => '图片表']); $table = $this->table('sys_image', ['engine' => 'MyISAM', 'comment' => '图片表']);
$table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID']) $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_path', 'string', ['limit' => 125, 'null' => false, 'comment' => '图片路径'])
->addColumn('image_thumb', 'string', ['limit' => 125, 'null' => false, 'comment' => '缩略图路径']) ->addColumn('image_thumb', 'string', ['limit' => 125, 'null' => false, 'comment' => '缩略图路径'])
->addColumn('image_size', 'integer', ['null' => false, 'comment' => '图片大小']) ->addColumn('image_size', 'integer', ['null' => false, 'comment' => '图片大小'])