Codeigniter多文件上传 [英] Codeigniter multiple file upload

查看:119
本文介绍了Codeigniter多文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在codeigniter 2中,我必须进行多文件上传。

In codeigniter 2 I have to do a multiple file upload.

在我看来,输入元素如下

In my view input elements looks like this

<input type="file" name="file[]" id="file_1" />
<input type="file" name="file[]" id="file_2" />
<input type="file" name="file[]" id="file_3" />
<input type="file" name="file[]" id="file_4" />
<input type="file" name="file[]" id="file_5" />
<input type="file" name="file[]" id="file_6" />

Plese帮助我如何写控制器来上传这些文件.. googled很多..谢谢

Plese help me how to write the controller to upload these files .. googled a lot .. Thanks in advance

推荐答案

您可以上传任意数量的文件

You can upload any number of files

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

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

    if (!empty($value['tmp_name']) && $value['size'] > 0) {

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

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

        } else {
            // Code After Files Upload Success GOES HERE
        }
    }
}

尝试使用这样的HTML:

And try using HTML like this:

<input type="file" name="file1" id="file_1" />
<input type="file" name="file2" id="file_2" />
<input type="file" name="file3" id="file_3" />

这篇关于Codeigniter多文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆