0

我在使用 codeigniter 时遇到了多个上传文件的问题。我之前尝试过很多方法,但仍然没有成功。

这是我的代码。

看法

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

内表:

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

控制器

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

我也试过这个方法,但没有上传文件。

$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
                }
            }
        }
4

0 回答 0