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;

        }
    }

Recommended Answers

All 3 Replies

Hi riwakawd? Please try What helped MeI hope its the right answer.

Hi riwakawd? Please try What helped Me I hope its the right answer.

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

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