dev #4
|
@ -60,4 +60,15 @@ class UploadController extends BaseAdminController
|
|||
}
|
||||
}
|
||||
|
||||
public function file()
|
||||
{
|
||||
try {
|
||||
$cid = $this->request->post('cid', 0);
|
||||
$result = UploadService::file($cid);
|
||||
return $this->success('上传成功', $result);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\AppUpdate;
|
||||
|
||||
class AppUpdateController extends BaseApiController
|
||||
{
|
||||
public function index() {
|
||||
$data = AppUpdate::field('id,title,content,type,version,dow_url,force,quiet')->where('')->order('id desc')->findOrEmpty();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
}
|
|
@ -161,4 +161,61 @@ class UploadService
|
|||
}
|
||||
}
|
||||
|
||||
public static function file($cid, int $sourceId = 0, int $source = FileEnum::SOURCE_ADMIN, string $saveDir = 'uploads/file')
|
||||
{
|
||||
try {
|
||||
$config = [
|
||||
'default' => ConfigService::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigService::get('storage') ?? ['local'=>[]],
|
||||
];
|
||||
|
||||
// 2、执行文件上传
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
$StorageDriver->setUploadFile('file');
|
||||
$fileName = $StorageDriver->getFileName();
|
||||
$fileInfo = $StorageDriver->getFileInfo();
|
||||
// 校验上传文件后缀
|
||||
if (!in_array(strtolower($fileInfo['ext']), config('project.file_file'))) {
|
||||
throw new Exception("上传文件不允许上传". $fileInfo['ext'] . "文件");
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
$saveDir = $saveDir . '/' . date('Ymd');
|
||||
if (!$StorageDriver->upload($saveDir)) {
|
||||
throw new Exception($StorageDriver->getError());
|
||||
}
|
||||
|
||||
// 3、处理文件名称
|
||||
if (strlen($fileInfo['name']) > 128) {
|
||||
$name = substr($fileInfo['name'], 0, 123);
|
||||
$nameEnd = substr($fileInfo['name'], strlen($fileInfo['name'])-5, strlen($fileInfo['name']));
|
||||
$fileInfo['name'] = $name . $nameEnd;
|
||||
}
|
||||
|
||||
// 4、写入数据库中
|
||||
$file = File::create([
|
||||
'cid' => $cid,
|
||||
'type' => FileEnum::VIDEO_TYPE,
|
||||
'name' => $fileInfo['name'],
|
||||
'uri' => $saveDir . '/' . str_replace("\\","/", $fileName),
|
||||
'source' => $source,
|
||||
'source_id' => $sourceId,
|
||||
'create_time' => time(),
|
||||
]);
|
||||
|
||||
// 5、返回结果
|
||||
return [
|
||||
'id' => $file['id'],
|
||||
'cid' => $file['cid'],
|
||||
'type' => $file['type'],
|
||||
'name' => $file['name'],
|
||||
'uri' => FileService::getFileUrl($file['uri']),
|
||||
'url' => $file['uri']
|
||||
];
|
||||
|
||||
} catch (Exception $e) {
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -42,7 +42,7 @@ abstract class Server
|
|||
}
|
||||
|
||||
// 校验上传文件后缀
|
||||
$limit = array_merge(config('project.file_image'), config('project.file_video'));
|
||||
$limit = array_merge(config('project.file_image'), config('project.file_video'),config('project.file_file'));
|
||||
if (!in_array(strtolower($this->file->extension()), $limit)) {
|
||||
throw new Exception('不允许上传' . $this->file->extension() . '后缀文件');
|
||||
}
|
||||
|
|
|
@ -74,6 +74,11 @@ return [
|
|||
'wmv', 'avi', 'mpg', 'mpeg', '3gp', 'mov', 'mp4', 'flv', 'f4v', 'rmvb', 'mkv'
|
||||
],
|
||||
|
||||
// 文件上传限制 (文件)
|
||||
'file_file' => [
|
||||
'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'txt','apk','ipa','wgt'
|
||||
],
|
||||
|
||||
// 登录设置
|
||||
'login' => [
|
||||
// 登录方式:1-账号密码登录;2-手机短信验证码登录
|
||||
|
|
Loading…
Reference in New Issue