无法在CodeIgniter中上传图像

时间:2012-11-13 03:37:43

标签: php codeigniter

我无法在Codeigniter中上传图片。

始终显示您尝试上传的文件类型不被允许。

我的编码(控制器):

$this->load->helper(array('form', 'url'));
            $this->load->library('upload');
            $config['upload_path'] = "./public/uploadimg";
            $config['allowed_types'] = "*";
            $config['max_size'] = '10000';

            $this->upload->initialize($config);

            if ( ! $this->upload->do_upload('userfile'))
            {
                echo $this->upload->display_errors();
                //$this->load->view('upload_form', $error);
            }
            else
            {
                echo $this->upload->data($config);
                //$this->load->view('upload_success', $data);
            }

查看:

<form  enctype="multipart/form-data" action="http://192.1.100.1/site/test_image/upload/" method="post">
    <input type="file"  name="userfile" id="userfile"/><Br>
    <input type="submit" name="upload" id="upload">
</form>

此致

2 个答案:

答案 0 :(得分:1)

尝试明确设置允许的类型。我记得之前遇到过同样的问题。

$config['allowed_types'] = 'docx|pdf|doc|gif|jpg|png|tiff'; 

答案 1 :(得分:0)

        $this->load->helper(array('form', 'url')); 
       if($this->input->post('upload')){ //submit name           

        $config['upload_path'] = "./public/uploadimg";
        $config['allowed_types'] = "png|jpg|jpeg";
        $config['max_size'] = '10000';
        $config['max_width'] = '1000';
        $config['max_height'] = '800';

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

        if ( ! $this->upload->do_upload('userfile')){
            echo $this->upload->display_errors();
            //$this->load->view('upload_form', $error);
            }
        else{
            echo $this->upload->data($config);
            //$this->load->view('upload_success', $data);
            }
        }

确保您的操作网址正确无误。抱歉,我的英语不好。