0

I got a problem with multiple upload file using codeigniter. I've tried many method before but still no success.

Here is my code.

View

<?php echo form_open_multipart('staff/upload_files', array('id' => 'form_checkbox')); ?>

Inside table:

     <tr>
        <th width="20%">Select File :</th>
        <td>
            <input type="file" name="userfile[]" value="" />&nbsp;<span class="green">[Max File Upload: 2MB]</span><br>
            <input type="file" name="userfile[]" value="" />&nbsp;<span class="green">[Max File Upload: 2MB]</span><br>
            <input type="file" name="userfile[]" value="" />&nbsp;<span class="green">[Max File Upload: 2MB]</span> 
        </td>
    </tr>

Controller

    function upload_files() {
        $data['studentid'] = $studentid;
        if ($this->input->post('submit')) {

            $config['upload_path'] = './upload/announcement/collegecode/';
            $config['allowed_types'] = 'jpg|png';
            $config['max_size'] = '2048';
            $config['max_width'] = '0';
            $config['max_height'] = '0';
            $config['overwrite'] = FALSE;

            $this->load->library('upload', $config);
            if (!$this->upload->do_upload()) {
                $this->session->set_flashdata('msg', 'error: ' . $this->upload->display_errors());
            } else {
                $this->session->set_flashdata('msg', 'success:Successfully Upload Student Photo');
            }
        }

        $this->template->load('template', 'staff/announcement', $data);
    }

I've also tried this method, but no file was uploaded.

$config['upload_path'] = './upload/announcement/collegecode/';
        $path=$config['upload_path'];
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['max_size'] = '2048';
        $config['max_width'] = '1920';
        $config['max_height'] = '1280';
        $this->load->library('upload');

        foreach ($_FILES as $key => $value)
        {


            if (!empty($key['userfile']))
            {


                $this->upload->initialize($config);
                if (!$this->upload->do_upload($key))
                {

                    $errors = $this->upload->display_errors();


                    flashMsg($errors);

                }
                else
                {
                     // Code After Files Upload Success GOES HERE
                }
            }
        }
Ae98
  • 43
  • 7

0 Answers0