<?php
/**
 * Extended / Overloaded CI-Upload Class to handle Flash-Form-Uploaded Images via Application/octet-stream
 *
 */
if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Extends the CodeIgniter Upload-Class
 */
class MY_Upload extends CI_Upload {
    /**
    * Verify that the filetype is allowed
    *
    * @return	bool
    */
    public function is_allowed_filetype($ignore_mime = FALSE)
    {
        if ($this->allowed_types == '*')
        {
            return TRUE;
        }

        if (count($this->allowed_types) == 0 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_types))
        {
            return FALSE;
        }

        // Images get some additional checks
        $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');

        if (in_array($ext, $image_types))
        {
            $gis = getimagesize($this->file_temp);
                if ($gis === FALSE)
                {
                        return FALSE;
                } else {
                 $this->file_type = $gis['mime'];
                }
        }

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

        $mime = $this->mimes_types($ext);

        if (is_array($mime))
        {
            if (in_array($this->file_type, $mime, TRUE))
                {
                        return TRUE;
                }
        }
        elseif ($mime == $this->file_type)
        {
            return TRUE;
        }

        return FALSE;
   }

}