0

When there should be a error it does not show. I can not seem to get the erorrs to work in the correct order How can I improve my file upload errors to work in correct order?

public function upload() {

        $name = $_FILES['userfile']['name']; 
        $tmp_name = $_FILES['userfile']['tmp_name']; 
        $type = $_FILES['userfile']['type']; 
        $size = $_FILES['userfile']['size']; 
        $error = $_FILES['userfile']['error']; 

        for($i = 0; $i < count($tmp_name); $i++) { 

            $dir = FCPATH . "upload/";

            if (is_dir($dir)) {

                if (!empty($name[$i]) && is_file($name[$i])) {

                        // Allowed file extension types
                    $allowed = array(
                        'jpg',
                        'jpeg',
                        'gif',
                        'png'
                    );

                    if (in_array(utf8_strtolower(utf8_substr(strrchr($name[$i], '.'), 1)), $allowed)) {
                        $this->error['warning'] = 'Incorrect File Type';
                    }

                    // Allowed file mime types
                    $allowed = array(
                        'image/jpeg',
                        'image/pjpeg',
                        'image/png',
                        'image/x-png',
                        'image/gif'
                    );

                    if (in_array($name[$i], $allowed)) {
                        $this->error['warning'] = 'Incorrect File Type';
                    }

                } else {

                    if (move_uploaded_file($tmp_name[$i], $dir . $name[$i])) { 
                        $this->error['warning'] = "move_uploaded_file function failed for ".$name[$i]."<br>"; 
                    }
                }

            } else {
                $this->error['warning'] = 'Directory Not There.';
            }
        } 



        return !$this->error;
    }
}
2
Contributors
2
Replies
18
Views
2 Years
Discussion Span
Last Post by riwakawd
0

The array files for checking if extensions and mime files are not working correct I would like to be able to check file types before move upload. So it will check if file type is allowed

Edited by riwakawd: Update

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.