【问题标题】:Codeigniter how to upload image extention PNG and JPGCodeigniter如何上传图片扩展PNG和JPG
【发布时间】:2018-11-30 07:34:24
【问题描述】:

需要有关 Framework CodeIgniter 的帮助...现在我做了一个简单的上传功能。但是当我想上传文件“image.PNG”或“image.JPG”时,它会返回false..但是我上传了图像文件“image.png”或“image.jpg”我成功上传了。

我的控制器,我用这个设置配置

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

在文件 /application/config/mimes.php 中。我也加了

'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'),

还是不行..请帮帮我

【问题讨论】:

  • 尝试设置$config['file_ext_tolower'] = TRUE;
  • 还是不行。
  • 在使用@pradeep 的建议时,删除大写场景的代码。
  • $config['allowed_types'] = 'gif|jpg|png|PNG|JPG'; 就足够了,不需要更改mime类型,尝试添加jpegJPEG
  • @TusharWalzade 我已经尝试用小写更改扩展名,但仍然无效。

标签: php codeigniter file-upload


【解决方案1】:
 $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');
            }
        }

使用上面的代码,了解它的功能并根据它使用它。不要忘记加载文件上传库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 2017-11-13
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多