开发者

Can't upload Image CodeIgniter, filetype error

开发者 https://www.devze.com 2023-03-02 13:00 出处:网络
I have write below code : function upld_logo() { $config[\'upload_path\'] = \'./images/\'; $config[\'allowed_types\'] = \'gif|jpg|png\';

I have write below code :

function upld_logo()
     {
        $config['upload_path'] = './images/';
        $config['allowed_types'] = 'gif|jpg|png';


        $this->load->library('upload', $conf开发者_高级运维ig);

        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());

            $data['msg']='Sorry! Cant Upload' . $error['error'];
           $data['main_content']='message';
           $this->load->view('template',$data);


        }   
        else
        {
            //$data = array('upload_data' => $this->upload->data());

            $names = $this->upload->data();
            $k=$names['file_name'];


            $data['msg']='Your Logo Successfully Uploaded. ';
           $data['main_content']='message';
           $this->load->view('template',$data); 
        }

     }

When I upload Image file with name logo.gif it show error message :

The filetype you are attempting to upload is not allowed.


Find this code in your system->libraries->Upload.php line 200

$this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $this->file_type); 

and replace with this:

$this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']);


Yes I also got the same error. And if u change the $[allowed_types] = "*" (allowed all files) you will find that upload is success but your image file don't have a type!

I think there's something wrong with the CI library maybe?


I have spent some time with the same issue. You might find codeigniters default upload library is using a couple of deprecated PHP functions to find the files mime type.... Good luck, I'm still trying to patch it myself .

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号