TP5.1多文件上传报错SplFileObject::__construct(/tmp/phpvfQPvQ))
PHP代码
$dir = ROOT_PATH;
$upFile = request()->file();
if (!empty($upFile)) {
foreach ($upFile as $key => $file) {
$up_status = false;
switch ($key) {
case 'logo'://logo
$up_info = $file->rule('uniqid')->validate(['size' => 3145728, 'ext' => 'png'])->move($dir . '/');
if ($up_info) {
$up_status = true;
$data['logo'] = $up_info->getFilename();
} else {
// 上传失败获取错误信息
$reData['code'] = 202;
$reData['msg'] = "上传失败:" . $file->getError();
}
break;
case 'ad'://ad
$up_info = $file->rule('uniqid')->validate(['size' => 3145728, 'ext' => 'jpg,png,gif'])->move($dir . '/');
if ($up_info) {
$up_status = true;
$data['ad'] = $up_info->getFilename();;
} else {
// 上传失败获取错误信息
$reData['code'] = 202;
$reData['msg'] = "上传失败:" . $file->getError();
}
break;
}
}
}
Postman访问
|