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

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.