0

我想要一个多文件上传代码。

例如:

Koala.jpg
Penguins.jpg
Jellyfish.jpg

有输入文本,用户可以在其中设置图像的新名称。

用户现在将上传图像,新图像名称的输入文本是“动物”

现在,我想要的是当这个上传的输出应该是 Animals1.jpg、Animals2.jpg、Animals3.jpg。

问题是当我尝试上传所有这些图像时,只有一张图像正在上传。

我试图进行研究并在我的程序上应用了一些代码,但仍然无法正常工作。

控制器

public function do_upload() { 
    $config = array(
        'image_library' => 'gd2',
        'file_name'     => $this->input->post('finame'),
        'upload_path'   => './public/img/uploads',
        'upload_url'    => base_url().'public/img/uploads',
        'allowed_types' => 'gif|jpg|jpeg',
        'max_size'      => '1024KB',
        'max_width'     => '1024',
        'max_height'    => '768',
        'maintain_ratio'=> TRUE,
        'overwrite'     => false,
    );
    $this->load->library('upload', $config);
    if (!$this->upload->do_upload()) {
        $error_msg = "<div class='alert alert-error'>".$this->upload->display_errors()."</div>";
        $error = array('error' => $error_msg);
    } 
    else {
        $upload_data = $this->upload->data();
        $data['thumbnail_name'] = $upload_data['raw_name']. '_thumb' .$upload_data['file_ext'];
        $file_array = array(
            'image'         => $data['thumbnail_name'],
            'image_name'    => $upload_data['file_name'],
            //'description'   => "",
            'date_created'  => date('Y-m-d H:i:s', now()),
            'date_modified' => date('Y-m-d H:i:s', now()),
            'author'        => $this->session->userdata('username'),
            'size'          => $upload_data['file_size'],
            'type'          => $upload_data['image_type'],
            'width'         => $upload_data['image_width'],
            'height'        => $upload_data['image_height'],
            //'document_name' => $field,
            //'department'    => $field2,
            //'notes'         => "",
        );
        $this->session->set_userdata('image_print', $file_array);
        $this->load->database();
        $this->db->insert('tbl_image', $file_array);
        $data = array('upload_data' => $this->upload->data());
        $user_level['records']=$this->user_model->get_records();
        $this->load->view('v_dashboard/page/header_view', $user_level);
        $this->load->view('v_document/upload/upload_result_view', $data);
        $this->load->view('v_dashboard/page/footer_view');
    }
}

我的 HTML 上有这个

<label for="file"><strong>Select File To Upload:</strong></label>
<input type="file" name="userfile[]" multiple class="btn transcolor btn-file"/>
<br/><br/>

顺便说一句,我在我的数据库上使用 BLOB。

我试图参考这个链接

埃利斯拉布

GitHub

堆栈溢出

堆栈溢出

CodingLikeASir

4

1 回答 1

0

您必须运行 for 循环,直到上传图像文件的计数。

像这样:

for ($i=0; $i < count($_FILES['userfile']['name']); $i++)
{ 
  // function to add the image name one by one into database.
}
于 2014-11-10T10:04:12.007 回答