Welcome Guest, Not a member yet? Register   Sign In
File Upload allowed_types issue
#1

I am trying to upload a .jpeg file using the CI uploader. Doing a migration from C1 2.x to CI 3.0
Code:
$config['upload_path'] =  $this->imgUploadFolder;
$config['allowed_types'] = 'gif|jpg|png|JPG|GIF|PNG|jpeg|JPEG';
$config['max_size'] = '1000';
$config['file_name'] = $name;

//Load the upload library
$this->load->library('upload', $config);
//attempt upload
$this->upload->do_upload()) <-- is returing false due to invalid file type
To debug, I dumped the data coming to the upload library 
The file type is recognized as image/jpeg
File name is correctly displayed - jamesgregory.jpeg
File extension is correctly displayed as .jpeg
The is_allowed_filetype function in Upload.php returns FALSE.
PHP Code:
public function is_allowed_filetype($ignore_mime FALSE)
    {
        if (
$this->allowed_types === '*')
        {
            return 
TRUE;
        }

        if (empty(
$this->allowed_types) OR ! is_array($this->allowed_types))
        {
            
$this->set_error('upload_no_file_types');
            return 
FALSE;
        }

        
$ext strtolower(ltrim($this->file_ext'.'));

        if ( ! 
in_array($ext$this->allowed_typesTRUE))
        {
            return 
FALSE;
        }

        
// Images get some additional checks
        
if (in_array($ext, array('gif''jpg''jpeg''jpe''png'), TRUE) && @getimagesize($this->file_temp) === FALSE)
        {
            return 
FALSE;
        }

        if (
$ignore_mime === TRUE)
        {
            return 
TRUE;
        }

        if (isset(
$this->_mimes[$ext]))
        {
            return 
is_array($this->_mimes[$ext])
                ? 
in_array($this->file_type$this->_mimes[$ext], TRUE)
                : (
$this->_mimes[$ext] === $this->file_type);
        }

        return 
FALSE;
    } 

It seems to pass every check and end up at the final return FALSE. 
Stumped!
Reply
#2

(10-05-2016, 06:34 PM)krishg Wrote: I am trying to upload a .jpeg file using the CI uploader. Doing a migration from C1 2.x to CI 3.0
Code:
$config['upload_path'] =  $this->imgUploadFolder;
$config['allowed_types'] = 'gif|jpg|png|JPG|GIF|PNG|jpeg|JPEG';
$config['max_size'] = '1000';
$config['file_name'] = $name;

//Load the upload library
$this->load->library('upload', $config);
//attempt upload
$this->upload->do_upload()) <-- is returing false due to invalid file type
To debug, I dumped the data coming to the upload library 
The file type is recognized as image/jpeg
File name is correctly displayed - jamesgregory.jpeg
File extension is correctly displayed as .jpeg
The is_allowed_filetype function in Upload.php returns FALSE.
PHP Code:
public function is_allowed_filetype($ignore_mime FALSE)
    {
        if (
$this->allowed_types === '*')
        {
            return 
TRUE;
        }

        if (empty(
$this->allowed_types) OR ! is_array($this->allowed_types))
        {
            
$this->set_error('upload_no_file_types');
            return 
FALSE;
        }

        
$ext strtolower(ltrim($this->file_ext'.'));

        if ( ! 
in_array($ext$this->allowed_typesTRUE))
        {
            return 
FALSE;
        }

        
// Images get some additional checks
        
if (in_array($ext, array('gif''jpg''jpeg''jpe''png'), TRUE) && @getimagesize($this->file_temp) === FALSE)
        {
            return 
FALSE;
        }

        if (
$ignore_mime === TRUE)
        {
            return 
TRUE;
        }

        if (isset(
$this->_mimes[$ext]))
        {
            return 
is_array($this->_mimes[$ext])
                ? 
in_array($this->file_type$this->_mimes[$ext], TRUE)
                : (
$this->_mimes[$ext] === $this->file_type);
        }

        return 
FALSE;
    } 

It seems to pass every check and end up at the final return FALSE. 
Stumped!
This was a config issue. I had overlooked to copy mimes.php from the 3.1.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB