CI_Upload::is_allowed_filetype PHP Method

is_allowed_filetype() public method

Verify that the filetype is allowed
public is_allowed_filetype ( boolean $ignore_mime = FALSE ) : boolean
$ignore_mime boolean
return boolean
    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', 'debug');
            return FALSE;
        }
        $ext = strtolower(ltrim($this->file_ext, '.'));
        if (!in_array($ext, $this->allowed_types, TRUE)) {
            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;
    }

Usage Example

Example #1
0
 /**
  * Verify that the filetype is allowed
  *
  * @access	public
  * @return	bool
  */
 function is_allowed_filetype()
 {
     if (count($this->allowed_types) == 0 or !is_array($this->allowed_types)) {
         $this->set_error('upload_no_file_types');
         return FALSE;
     }
     // Fix for 'application/octet-stream' problem in SWFUpload
     if ($this->file_type == 'application/octet-stream') {
         $mime = $this->mimes_types(trim($this->file_ext, '.'));
         $this->file_type = is_array($mime) ? $mime[0] : $mime;
     }
     // Match the mime with the actual extension
     $this->file_ext = strtolower($this->file_ext);
     if (CI()->CONF['match_mime_to_ext']) {
         // This will require that the extension of the file uploaded matches against only the extention's mimes
         if (in_array(trim($this->file_ext, '.'), $this->allowed_types)) {
             $mime = $this->mimes_types(trim($this->file_ext, '.'));
             if (is_array($mime) && in_array($this->file_type, $mime, TRUE)) {
                 return TRUE;
             } else {
                 if ($mime == $this->file_type) {
                     return TRUE;
                 }
             }
         }
         return FALSE;
     } else {
         return parent::is_allowed_filetype();
     }
 }
All Usage Examples Of CI_Upload::is_allowed_filetype