Welcome Guest, Not a member yet? Register   Sign In
Upload File Bug
#27

[eluser]mcnux[/eluser]
I've just gone through the is_allowed_filetype method and have come up with the following to fix the mixing images with other file types bug.

Essentially it first checks that the mime type matches before checking for valid image, which is what the function should have been doing in the first place - you don't want to check that the image is valid before you know that you have an image!

Had a quick test and appears to be fine. Also a few lines less than the original ;-)

Code:
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;
        }

        $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');

        foreach ($this->allowed_types as $val)
        {
            $mime = $this->mimes_types(strtolower($val));
            // force $mime into an array
            if (!is_array($mime))
            {
                $mime = array($mime);
            }
            
            if (in_array($this->file_type,$mime,TRUE))
            {
                // matched file type
                
                if (in_array($val,$image_types))
                {
                    // check image is ok
                    if (getimagesize($this->file_temp) === FALSE)
                    {
                        return FALSE;
                    }
                }
                
                // super
                return TRUE;
            }
        }
        
        // didn't match
        return FALSE;
    }


Messages In This Thread
Upload File Bug - by El Forum - 04-29-2009, 01:00 PM
Upload File Bug - by El Forum - 05-05-2009, 09:30 AM
Upload File Bug - by El Forum - 05-05-2009, 09:34 AM
Upload File Bug - by El Forum - 05-07-2009, 08:45 AM
Upload File Bug - by El Forum - 05-07-2009, 09:08 AM
Upload File Bug - by El Forum - 05-07-2009, 04:03 PM
Upload File Bug - by El Forum - 05-20-2009, 12:08 AM
Upload File Bug - by El Forum - 05-20-2009, 08:42 AM
Upload File Bug - by El Forum - 05-20-2009, 09:21 PM
Upload File Bug - by El Forum - 05-20-2009, 09:56 PM
Upload File Bug - by El Forum - 05-20-2009, 10:20 PM
Upload File Bug - by El Forum - 05-20-2009, 10:31 PM
Upload File Bug - by El Forum - 05-20-2009, 10:59 PM
Upload File Bug - by El Forum - 05-20-2009, 11:40 PM
Upload File Bug - by El Forum - 05-21-2009, 12:44 AM
Upload File Bug - by El Forum - 05-21-2009, 01:10 AM
Upload File Bug - by El Forum - 05-21-2009, 05:01 AM
Upload File Bug - by El Forum - 05-21-2009, 06:15 AM
Upload File Bug - by El Forum - 06-10-2009, 09:22 PM
Upload File Bug - by El Forum - 06-11-2009, 12:38 AM
Upload File Bug - by El Forum - 06-17-2009, 11:16 AM
Upload File Bug - by El Forum - 06-18-2009, 09:25 AM
Upload File Bug - by El Forum - 06-29-2009, 12:00 AM
Upload File Bug - by El Forum - 06-29-2009, 12:03 AM
Upload File Bug - by El Forum - 07-13-2009, 07:40 PM
Upload File Bug - by El Forum - 08-28-2009, 01:56 AM
Upload File Bug - by El Forum - 08-28-2009, 09:32 AM
Upload File Bug - by El Forum - 09-04-2009, 08:00 PM
Upload File Bug - by El Forum - 09-29-2009, 02:28 AM
Upload File Bug - by El Forum - 09-29-2009, 02:38 PM
Upload File Bug - by El Forum - 10-01-2009, 01:05 AM
Upload File Bug - by El Forum - 10-01-2009, 01:12 AM
Upload File Bug - by El Forum - 10-22-2009, 01:13 PM
Upload File Bug - by El Forum - 07-11-2011, 02:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB