1

I'm yet to find a perfect solution where with codeigniter my visitors can upload jpeg extension of the image, my visitors won't convert anything, so is there a work around so we can all jpeg extensions, here is current code which gives error invalid image extension error.

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); 

previously i had just $config['allowed_types'] = 'jpg|png

but after complaints i added $config['allowed_types'] = 'jpeg|jpg|png'

but it is not working at all.

8
  • Ok have you checked your uploaded image extension ? Commented Aug 13, 2015 at 10:11
  • Check out the uploaded image mime type. Commented Aug 13, 2015 at 10:11
  • @AnkiiGangrade can you help how to do that? Commented Aug 13, 2015 at 10:12
  • Try to print $this->upload->data() and check file_type:The file's Mime type. Commented Aug 13, 2015 at 10:16
  • @AsimShahzad it is not uploading at all, works find with jpg and png but not with jpeg Commented Aug 13, 2015 at 10:16

2 Answers 2

1

This one worked for me in codeigniter 3.

N/B: Works for the .jfif extension images

Open your config file mimes.php and add this line

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

Then in your upload configuration, use this configuration for allowed types

$config['allowed_types'] = 'gif|jpg|png|JPG|GIF|PNG|jpeg|JPEG|jfif|JFIF';
Sign up to request clarification or add additional context in comments.

Comments

0

Although it is not tested, but you can try this:

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);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.