无法在codeigniter中上传文件

时间:2015-11-25 13:03:59

标签: php codeigniter

每当我尝试按“上传文件”上传文件时选择之后,它会将我引导到一个空白页面。请查看官方文档以及youtube上的各种视频。

 public function index()
{
    $this->load->view('upload_form');
}
  //upload_form
 <?php 
echo form_open_multipart(base_url()."index.php/home/upload_file");
echo form_upload("file");
echo form_submit("upload","Upload file");
?>
public function upload_file()
{
    if($this->input->post("upload")===false)
        return;

    $config['upload_path'] = "./uploads/";
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    //$config['max_width']  = '1024';
    //$config['max_height']  = '768';

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

    if (!$this->upload->do_upload("file"))
    {
        $this->load->view("error");
        }
    else
    {
        $this->load->view("success");
    }
}

错误和成功页面只是简单的文本。

1 个答案:

答案 0 :(得分:0)

($this->input->post("upload")===false)

不起作用。请改用:

if(!empty($_FILES['upload']['name'])) { 
    ...
}