修改文件上传,文件后缀验证机制

This commit is contained in:
邹景立 2021-09-15 16:34:12 +08:00
parent b1fab14623
commit 0bf173c5d7

View File

@ -112,7 +112,7 @@ class Upload extends Controller
$extension = strtolower($file->getOriginalExtension());
$saveName = input('key') ?: Storage::name($file->getPathname(), $extension, '', 'md5_file');
// 检查文件后缀是否被恶意修改
if (ltrim(strtolower(strrchr($saveName, '.')), '.') !== $extension) {
if (pathinfo(parse_url($saveName, PHP_URL_PATH), PATHINFO_EXTENSION) !== $extension) {
$this->error('文件后缀异常,请重新上传文件!');
}
// 屏蔽禁止上传指定后缀的文件