我试图将图像上传到指定的文件夹,但无法弄清楚为什么控制器功能不起作用。这是控制器代码
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '400';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload',$config);
if($this->upload->do_upload()){
echo "image uploaded";
}
echo $this->input->post('username');
}
这是在视图文件夹中输入图像文件的表单
<form enctype="multipart/form-data" method="post" action="<?php echo site_url('welcome/do_upload');?>">
username:<input type="text" name="username">
<p>upload file</p>
<input type="file" name="image">
<input type="submit" name="submit" value="submit">
</form>
答案 0 :(得分:0)
你只需要在do_upload函数中传递文件输入名称'image',默认情况下是'userfile'
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '400';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload',$config);
if($this->upload->do_upload('image')){ //passed 'image' file control input name in form
echo "image uploaded";
}
echo $this->input->post('username');
}