Codeigniter不上传jpeg图像



我还没有找到一个完美的解决方案,与codeigniter我的访客可以上传图像的jpeg扩展,我的访客不会转换任何东西,所以有一个工作,所以我们可以所有的jpeg扩展,这里是当前的代码给出错误invalid image extension错误。

i'm not uploading whole code to save time and any confusion

$config['upload_path'] = 'upload/path/folder';
$config['allowed_types'] = 'jpeg|jpg|png';
$config['max_size'] = '262144';
$config['file_name'] = 'file_name';
$config['overwrite'] = TRUE;
$this->load->library('upload',$config); 

之前我只有$config['allowed_types'] = 'jpg|png

投诉后加入$config['allowed_types'] = 'jpeg|jpg|png'

这个在codeigniter 3中为我工作。

N/B:适用于。jfif扩展名images

打开配置文件mime .php并添加以下行

'jfif'  =>  array('image/jpeg', 'image/pjpeg'),

然后在您的上传配置中,对允许的类型使用此配置

$config['allowed_types'] = 'gif|jpg|png|JPG|GIF|PNG|jpeg|JPEG|jfif|JFIF';

虽然没有经过测试,但是您可以试试:

public function do_upload(){
    $config = array(
    'upload_path' => "./uploads/",
    'allowed_types' => "gif|jpg|png|jpeg|pdf|docx",
    'overwrite' => TRUE,
    'max_size' => "2048000", //File Size
    'max_height' => "768",
    'max_width' => "1024"
    );
    $this->load->library('upload', $config);
    if($this->upload->do_upload())
    {
       $data = array('upload_data' => $this->upload->data());
       $this->load->view('upload_success',$data);
    }
    else
    {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('file_view', $error);
    }
}

最新更新