0

When I upload I can upload single files fine but, I cannot seem to upload if input is like <input type="file" name="file[]">

I am not sure on my php upload function how to make it allow multiple files?

Thanks in advance.

public function upload() {
        $this->load->library('request');

        $directory = FCPATH .'upload/';
        $full_path = $directory . basename($this->request->files['file']['name']);
        $file_name = basename($this->request->files['file']['name']);
        $file_ext = array('jpeg', 'jpg', 'gif','png');
        $file_size = 3000;

        if (is_dir($directory)) {

            if (!move_uploaded_file($this->request->files['file']['tmp_name'], $full_path)) {

                if (!in_array(utf8_strtolower(utf8_substr(strrchr($file_name, '.'), 1)), $file_ext)) {
                    $this->error['warning'] = 'Warning: Incorrect file type!';
                }

                if ($_FILES["file"]["size"] < $file_size) {
                    $this->error['warning'] = 'Warning: Incorrect file size!';
                }

                return !$this->error;
            }

        } else {

            $this->error['warning'] = 'Warning: Directory does not exist!';

            return !$this->error;

        }
    }
2
Contributors
3
Replies
29
Views
2 Years
Discussion Span
Last Post by riwakawd
0

@Bile Thanks for advice Just a question I have got it working but need to set it so it checks the file size and then file_ext before upload what would you recommend

public function upload() {
        $this->load->library('request');

        $file_path = FCPATH .'upload/';
        $file_name = $this->request->files['file']['name'];
        $file_tmp = $this->request->files['file']['tmp_name'];
        $file_type = $this->request->files['file']['type'];
        $file_size = $this->request->files['file']['size'];
        $file_error = $this->request->files['file']['error'];
        $file_ext = array('png', 'gif', 'ico');
        $file_max_size = 100;

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

            if (move_uploaded_file($file_tmp[$i], $file_path . $file_name[$i])) {

            } else {

                if ($file_name < $file_max_size) {

                    $this->error['waring'] = 'Warning: File'.' '.$file_name[$i].' '.'is more than'.' '.$file_max_size.' '.'KB';

                } else {

                    continue;
                }
            }

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