doucuyu2259 2018-06-21 04:47
浏览 48

Codeigniter如何上传图片扩展名PNG和JPG

need help with Framework CodeIgniter... now i made a simple upload function. but when i want to upload file "image.PNG" or "image.JPG" it will return false.. but went i upload image file "image.png" or "image.jpg" i sucess upload it.

i controllers, i set the config with this

$config['allowed_types']  = 'gif|jpg|png|PNG|JPG'; 

and in file /application/config/mimes.php. i also added

'png'   =>  array('image/png',  'image/x-png'), 
'PNG'   =>  array('image/PNG',  'image/x-PNG'),  
'jpg'   =>  array('image/jpeg', 'image/pjpeg'),
'JPG'   =>  array('image/jpeg', 'image/pjpeg'),

still can't work.. please help me

  • 写回答

1条回答 默认 最新

  • dongzhuang6177 2018-06-21 05:52
    关注
     $config['upload_path']    = FCPATH.'assets/college/images/logo/';
            $config['allowed_types']  = 'gif|jpg|png|jpeg';
            $config['max_size']       = 1000;
            $config['max_width']      = 500;
            $config['max_height']     = 500;
            $config['min_height']     = 300;
            $config['min_width']      = 300;
            $config['file_ext_tolower'] = TRUE;
            $config['file_name'] = uid().'_logo_'.date('YmdHis');
            $this->load->library('upload', $config);
            $this->upload->initialize($config);
            if ( ! $this->upload->do_upload('logo'))
            {
               set_alert('danger',htmlspecialchars(trim(strip_tags($this->upload->display_errors()))));
               redirect('somewhere');
            }
            else
            {
                $data = $this->upload->data();
                $logo['logo'] = $data['file_name'];
                $success = $this->institute_model->update_media($id,$logo);
                if($success != FALSE)
                {
                    set_alert('success','Your Logo has been successfully Updated');
                    redirect('institution/add_update');
                }
                else
                {
                    set_alert('danger','Your logo is not updated due to some technical reasons.Please try again');
                    redirect('institution/add_update');
                }
            }
    

    Use the code above, understand it functionality and use it according. Don't forgot to load the file upload library.

    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题