为什么do_upload不起作用,并且未显示错误图像?

时间:2017-06-07 17:53:47

标签: php codeigniter-3

这是我的查看代码。

 <?=form_open_multipart('test/uploadimage/add_image',['class'=>'']);?>
<?=form_upload(['name'=>'img1','class'=>'form-control']); ?>
 <?=form_input(['name'=>'add','type'=>'submit','value'=>'Add']);?>
<?php if(isset($upload_error)) echo $upload_error?>
 <?=form_close(); ?>

这是我的控制器,我想在add_image函数中上传图片。

<?php
  class  Uploadimage extends MY_Controller{
  function index(){
    $this->load->view('test/upload_image');
       }
 function  add_image(){
    $config=[
             'upload_path'=>'./uploads',
             'allowed_types'=>'png|gif|jpg',

          ];
    $this->load->library('upload',$config);
    if($this->upload->do_upload()){
        echo 'succee';
    }
   else {
        echo 'failled';
        $upload_error= $this->upload->display_errors();
        $this->load->view('test/upload_image',compact('upload_error'));
      }
   }
  }
 ?>

显示错误

enter image description here

1 个答案:

答案 0 :(得分:0)

在代码中更改此行。

$this->upload->do_upload();

$this->upload->do_upload('img1');