繁体   English   中英

如何使用CodeIgniter编码多个文件上传?

[英]How to code multiple file upload using CodeIgniter?

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

例如:

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

堆栈溢出

堆栈溢出

编码类似

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

像这样:

for ($i=0; $i < count($_FILES['userfile']['name']); $i++)
{ 
  // function to add the image name one by one into database.
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM