简体   繁体   English

Codeigniter如何上传图像扩展PNG和JPG

[英]Codeigniter how to upload image extention PNG and JPG

need help with Framework CodeIgniter... now i made a simple upload function. 在Framework CodeIgniter方面需要帮助...现在,我做了一个简单的上传功能。 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. 但是,当我要上传文件“ image.PNG”或“ image.JPG”时,它将返回false ..但是我上传了图像文件“ image.png”或“ image.jpg”,因此我成功上传了该文件。

i controllers, i set the config with this 我的控制器,我用这个设置配置

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

and in file /application/config/mimes.php. 并在文件/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 仍然不能工作..请帮助我

 $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. 不要忘记加载文件上传库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM