【问题标题】:Codeigniter multiple file uploadCodeigniter 多文件上传
【发布时间】:2012-03-05 19:31:03
【问题描述】:

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

在我看来,输入元素看起来像这样

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

请帮助我如何编写控制器来上传这些文件.. google了很多..提前谢谢

【问题讨论】:

  • Google 说了什么?你试过什么? $_FILES 怎么说?
  • 试过什么?到目前为止发布您的代码。此外,您可以在 SO 上找到许多类似的问题;使用本机上传类进行多次上传几乎只是使用循环的问题。例如,stackoverflow.com/questions/1908247/…
  • 在我的控制器中我刚刚写了 $images=$_FILES['file']; $res=$this->admins->addPlace($insertdata,$images);它只是将它发送到我的管理员模型。在那里我被循环困住了..请帮助

标签: php codeigniter file-upload multifile-uploader


【解决方案1】:

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

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

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

【讨论】:

  • 您好,感谢您的回复,我收到此错误...请帮助遇到 PHP 错误严重性:通知消息:数组到字符串转换文件名:libraries/Upload.php 行号:161
  • 嗨 srbhbarot .. 请在下面找到我的答案 .. 我遇到的错误 .. 请帮忙
  • 对不起,我无法回答我自己.. 现在我收到此错误您没有选择要上传的文件。
  • 总是尝试测试数据水平低的代码。首先将文件标签的名称更改为 file1,file2....,然后尝试使用最小尺寸的图像。
  • 这不是正确的解决方案。 Upload 库使用 $_FILES 超全局变量进行验证和错误处理,并始终将其视为单个文件上传。
猜你喜欢
  • 2013-07-31
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 2011-04-08
  • 2016-08-28
  • 2012-01-12
相关资源
最近更新 更多