这是我的查看代码。
<?=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'));
}
}
}
?>
显示错误:
答案 0 :(得分:0)
在代码中更改此行。
$this->upload->do_upload();
与
$this->upload->do_upload('img1');