【问题标题】:Multiple file upload with Codeigniter 3使用 Codeigniter 3 上传多个文件
【发布时间】:2015-04-28 20:41:12
【问题描述】:

我正在尝试上传多张图片。

我的表格是这样的:

<form>
  <input type="file" name="images[]">
  <input type="file" name="images[]">
  <input type="file" name="images[]">
</form>

我知道这个表格是对的。当 Codeigniter 尝试上传文件时出现错误。

function do_upload_images() {
    $files = $_FILES;

    $cpt = count ( $_FILES ['images'] ['name'] );
    for($i = 0; $i < $cpt; $i ++) {

        $_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i];
        $_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i];
        $_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i];
        $_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i];
        $_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i];

        $this->upload->initialize ( $this->set_upload_options () );
        $this->upload->do_upload ($_FILES['images']);
    }
}
private function set_upload_options() {
    // upload an image options
    $config = array ();
    $config ['upload_path'] = './uploads/estate_images';
    $config ['allowed_types'] = 'gif|jpg|png';
    $config ['encrypt_name'] = TRUE;

    return $config;
}

这是我得到的错误:

消息:isset 中的非法偏移类型或空文件名: 库/Upload.php 行号:377

【问题讨论】:

标签: codeigniter


【解决方案1】:

我自己得到解决方案。只需要更改以下行:

$this->upload->do_upload ($_FILES['images']);

$this->upload->do_upload ('images');

【讨论】:

  • 真的有效吗?! do_upload() 似乎期待字符串而不是数组?!
  • 既然我们可以返回一个数据数组,所有的信息文件都上传了吗?
猜你喜欢
  • 2023-03-22
  • 2015-01-07
  • 2014-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-08
相关资源
最近更新 更多