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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度