CodeIgniter Forums
Allowmultiple file upload problem solved. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Allowmultiple file upload problem solved. (/thread-30844.html)



Allowmultiple file upload problem solved. - El Forum - 05-27-2010

[eluser]alvk4r[/eluser]
If you try upload a file through an upload config with various mime types and include an image ext. i.e (png|pdf), then you could upload the image, but the other file report an error.

I make some changes into the core library Upload (/system/libraries/Upload.php).
The change don't affect the functionality of the class, I only change the location of one validation statement.

You can view a diff for details.

I attach the file modified.

There is the full code of method modified, make it simple copy & paste replacing the method:

Code:
/**
     * 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;
        }
        
        $image_types = array ('gif', 'jpg', 'jpeg', 'png', 'jpe' );
        
        foreach ( $this->allowed_types as $val ) {
            $mime = $this->mimes_types ( strtolower ( $val ) );
            
            if (is_array ( $mime )) {
                if (in_array ( $this->file_type, $mime, TRUE )) {

                    // Images get some additional checks
                    if (in_array ( $val, $image_types )) {
                        if (getimagesize ( $this->file_temp ) === FALSE) {
                            return FALSE;
                        }
                    }
                    return TRUE;
                }
            } else {
                if ($mime == $this->file_type) {
                    return TRUE;
                }
            }
        
        }
        
        return FALSE;
    }



Allowmultiple file upload problem solved. - El Forum - 06-08-2010

[eluser]danmontgomery[/eluser]
This issue is fixed in 2.0 as well.

http://bitbucket.org/ellislab/codeigniter/changeset/4ce5f465478a