官网专刊上传文件添加20M的限制
This commit is contained in:
@@ -923,11 +923,21 @@ class Special extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文章的文件
|
* 上传文章的文件
|
||||||
|
* coverLetter / picturesAndTables / manuscirpt 限制不超过 20M
|
||||||
*/
|
*/
|
||||||
public function up_file($type)
|
public function up_file($type)
|
||||||
{
|
{
|
||||||
$file = request()->file($type);
|
$file = request()->file($type);
|
||||||
if ($file) {
|
if ($file) {
|
||||||
|
$limitTypes = ['coverLetter', 'picturesAndTables', 'manuscirpt'];
|
||||||
|
if (in_array($type, $limitTypes, true)) {
|
||||||
|
$maxSize = 20 * 1024 * 1024;
|
||||||
|
$fileInfo = $file->getInfo();
|
||||||
|
$fileSize = isset($fileInfo['size']) ? intval($fileInfo['size']) : 0;
|
||||||
|
if ($fileSize > $maxSize) {
|
||||||
|
return json(['code' => 1, 'msg' => 'File size cannot exceed 20MB']);
|
||||||
|
}
|
||||||
|
}
|
||||||
$info = $file->move(ROOT_PATH . 'public' . DS . $type);
|
$info = $file->move(ROOT_PATH . 'public' . DS . $type);
|
||||||
if ($info) {
|
if ($info) {
|
||||||
return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
|
return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
|
||||||
@@ -1046,7 +1056,7 @@ class Special extends Controller
|
|||||||
$specials = isset($res['specials']) ? $res['specials'] : (isset($res['data']['specials']) ? $res['data']['specials'] : []);
|
$specials = isset($res['specials']) ? $res['specials'] : (isset($res['data']['specials']) ? $res['data']['specials'] : []);
|
||||||
foreach ($specials as $k => $v) {
|
foreach ($specials as $k => $v) {
|
||||||
unset($specials[$k]['abstract']);
|
unset($specials[$k]['abstract']);
|
||||||
$specials[$k]['icon'] = $specials[$k]['icon']?$journal_image_url."specialIcon/".$specials[$k]['icon']:"";
|
$specials[$k]['icon'] = $specials[$k]['icon']?$journal_image_url."journalicon/".$specials[$k]['icon']:"";
|
||||||
}
|
}
|
||||||
$re['specials'] = $specials;
|
$re['specials'] = $specials;
|
||||||
$re['count'] = isset($res['data']['count']) ? intval($res['data']['count']) : 0;
|
$re['count'] = isset($res['data']['count']) ? intval($res['data']['count']) : 0;
|
||||||
@@ -2078,28 +2088,31 @@ class Special extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传专刊封面图(转发至 journal Special/up_icon_file)
|
* 上传专刊封面图(转发至 journal master/Journal/up_file)
|
||||||
* 表单字段名:specialIcon
|
* 入参表单字段兼容 specialIcon / journalicon;转发官网时使用 journalicon
|
||||||
*/
|
*/
|
||||||
public function up_icon_file()
|
public function up_icon_file()
|
||||||
{
|
{
|
||||||
$file = request()->file('specialIcon');
|
$file = request()->file('specialIcon');
|
||||||
|
if (!$file) {
|
||||||
|
$file = request()->file('journalicon');
|
||||||
|
}
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
return jsonError('specialIcon is required');
|
return jsonError('specialIcon is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
$info = $file->getInfo();
|
$info = $file->getInfo();
|
||||||
$tmpPath = isset($info['tmp_name']) ? $info['tmp_name'] : '';
|
$tmpPath = isset($info['tmp_name']) ? $info['tmp_name'] : '';
|
||||||
$originName = isset($info['name']) ? $info['name'] : 'specialIcon';
|
$originName = isset($info['name']) ? $info['name'] : 'journalicon';
|
||||||
$mime = isset($info['type']) && $info['type'] !== '' ? $info['type'] : 'application/octet-stream';
|
$mime = isset($info['type']) && $info['type'] !== '' ? $info['type'] : 'application/octet-stream';
|
||||||
if ($tmpPath === '' || !is_file($tmpPath)) {
|
if ($tmpPath === '' || !is_file($tmpPath)) {
|
||||||
return jsonError('upload file invalid');
|
return jsonError('upload file invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
$base_url = Env::get('journal.base_url');
|
$base_url = Env::get('journal.base_url');
|
||||||
$url = rtrim($base_url, '/') . '/api/Special/up_icon_file';
|
$url = rtrim($base_url, '/') . '/master/Journal/up_file';
|
||||||
$postFields = [
|
$postFields = [
|
||||||
'specialIcon' => new \CURLFile(realpath($tmpPath), $mime, $originName),
|
'journalicon' => new \CURLFile(realpath($tmpPath), $mime, $originName),
|
||||||
];
|
];
|
||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
|
|||||||
Reference in New Issue
Block a user