refactor: 修改图片上传区分模块
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -38,7 +38,7 @@ Route::group('v1', function () {
|
||||
// 图片管理
|
||||
Route::group('images', function () {
|
||||
// 图片上传
|
||||
Route::post('upload', 'Images/upload');
|
||||
Route::post('/:module/upload', 'Images/upload');
|
||||
});
|
||||
|
||||
// 文章模块
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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' => '图片大小'])
|
||||
|
||||
Reference in New Issue
Block a user