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

[eluser]Unknown[/eluser]
Hopefully this helps. I tried every variation of the posts to try to get CI to accept PDF, INDD, AI, ZIP files and more. Messing with the mime types did not seem to help. I found a fix to add to the Upload.php file within the is_allowed_filetype function.

The problem seems to be within the foreach loop. I don't claim to be a good programmer, but I think the fact that within every condition in this loop, there is a return true or return false which breaks the loop?? (feel free to correct me if I am wrong)

Here is my updated code:
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');
        
        /*
            Experienced errors with file types
            PDF     = application/pdf
            ZIP     = application/octet-stream
            INDD    = application/octet-stream
            ZIP     = application/zip
            AI      = application/postscript
        */
        $error_types = array(
                            'application/pdf',
                            'application/octet-stream',
                            'application/zip',
                            'application/postscript'
                            );
        
        foreach ($this->allowed_types as $val)
        {
            $mime = $this->mimes_types(strtolower($val));
                        
            // Images get some additional checks
            if (in_array($val, $image_types))
            {
                
                if (getimagesize($this->file_temp) === FALSE)
                {                    
                    // Added this condition for the error types
                    if (in_array($this->file_type, $error_types, TRUE))
                    {
                        return TRUE;
                    }
                    else
                    {
                        return FALSE;
                    }
                }
            }
            
            if (is_array($mime))
            {
                if (in_array($this->file_type, $mime, TRUE))
                {
                    return TRUE;
                }
            }
            else
            {
                if ($mime == $this->file_type)
                {
                    return TRUE;
                }    
            }        
        }
        
        return FALSE;
    }

If you add the file types you are experiencing errors with in that $error_types array, then the upload function works with those files you experience issues with where the mime type does not fix.

I hope this helps others who had the same issues as me.


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