donglankui1263 2014-11-30 10:53
浏览 42
已采纳

codeigniter没有显示文件上传错误

I am using CodeIgniter file uploading class to upload a image. But if I try and select a pdf instead of image I do not get any errors on form submission.

relevant code

$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();
  • 写回答

1条回答 默认 最新

  • dssjxvbv918586 2014-12-01 01:10
    关注

    It is because you never went to the documentation (here), please do so in order to perform better in CodeIgniter framework.


    this should give you heads up (please read comments)

    $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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?