跳过"You did not select a file to upload"错误并显示所有其他错误



当我上传图像时,我如何忽略"您没有选择要上传的文件"错误并在上传图像时显示所有其他错误?

for($i = 1; $i < 6; $i++) {
    $upload = $this->upload->do_upload('image'.$i);
    if (!$upload) {
        $error = array('error' => $this->upload->display_errors());
        var_dump($error);
    } else {
        $images = $this->upload->data();
    }
}

我想做的是当$upload失败时,因为没有文件上传,运行:

$images = $this->upload->data();

或显示其他图片上传错误。我该怎么做呢?

不能——没有其他错误或数据。如果您查看Upload库,您将看到它检查的第一件事(可以理解)是查看是否存在文件。如果没有文件,则设置错误并退出,因此不会处理其他任何内容:

// Is $_FILES[$field] set? If not, no reason to continue.
if ( ! isset($_FILES[$field]))
{
    $this->set_error('upload_no_file_selected');
    return FALSE;
}

相关内容

最新更新