gpt4 book ai didi

php - Codeigniter不显示文件上传错误

转载 作者:行者123 更新时间:2023-12-03 08:55:32 24 4
gpt4 key购买 nike

我正在使用CodeIgniter文件上传类上传图像。但是,如果我尝试选择pdf而不是图像,则在提交表单时不会出现任何错误。

相关代码

$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->article_path.'/magazine',
'max_size' => 2000
);

$this->load->library('upload', $config);
$this->upload->do_upload();
$this->upload->display_errors();
$image_data = $this->upload->data();

最佳答案

这是因为您从未使用过文档(here),所以请这样做是为了在CodeIgniter框架中表现更好。

这应该使您警惕(请阅读评论)

$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->article_path.'/magazine',
'max_size' => 2000
);

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload()) //important!
{
// something went really wrong show error page
$error = array('error' => $this->upload->display_errors()); //associate view variable $error with upload errors

$this->load->view('upload_form', $error); //show error page
}
else
{
//all is good we upload
$data = array('upload_data' => $this->upload->data());

$this->load->view('upload_success', $data);
}

关于php - Codeigniter不显示文件上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27212437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com