【问题标题】:CodeIgniter - uploading multiple files with one inputCodeIgniter - 使用一个输入上传多个文件
【发布时间】:2012-04-08 09:45:55
【问题描述】:

我正在尝试从一个输入一次上传多个文件

<input type="file" name="form-image[]" id="form-image" multiple="true" />

没有 CodeIgniter 的它本身可以正常工作。在我尝试使用 CodeIgniters 文件助手做同样的事情时;我收到一个错误 (is_uploaded_file() expects parameter 1 to be string, array given),这表明我做错了什么,或者 CodeIgniter 只是不支持多个文件?

到目前为止我的错误代码:

//Iterate through each file uploaded
for ($i = 0; isset($_FILES['form-image']['name'][$i]); $i++) {

   //Fix the settings
   $config['upload_path'] = "./static/vimmel/";
   $config['file_name'] = time() . rand(1,988);
   $config['allowed_types'] = 'gif|jpg|png';
   $config['max_size']  = '1024';
   $config['max_width']  = '1024';
   $config['max_height']  = '768';
   $this->load->library('upload', $config);

   //Do the upload
   $this->upload->do_upload("form-image")
}

请注意,我确实编辑了所有错误处理等。另请注意,我不使用is_uploaded_file() 函数。

感谢所有帮助和建议。谢谢。

【问题讨论】:

  • 我不确定 CI 是否支持多文件上传,如果可行,我会坚持你原来的方法,真正的线索就在“助手”这个名字中。如果对您没有帮助,请不要使用它。

标签: php html codeigniter file-upload


【解决方案1】:

CodeIgniter 不支持多个文件。在 foreach 中使用 do_upload() 与在外部使用它没有什么不同。

您需要在没有 CodeIgniter 帮助的情况下处理它。这是一个例子https://github.com/woxxy/FoOlSlide/blob/master/application/controllers/admin/series.php#L331-370

【讨论】:

    【解决方案2】:

    我正在使用 Upload 库的扩展,其中包含一个接受文件数组的 do_multiple_upload() 函数

    https://github.com/nicdev/CodeIgniter-Multiple-File-Upload

    它缺少一些错误管理(例如,如果您的一个文件没有允许的扩展名,则整个上传失败),但您可以在循环中更改 continue 的返回值。

    希望对某人有所帮助...

    【讨论】:

      猜你喜欢
      • 2014-09-26
      • 2020-07-25
      • 1970-01-01
      • 2013-10-18
      • 2023-02-12
      • 2019-05-18
      • 1970-01-01
      • 2018-03-19
      • 2019-07-23
      相关资源
      最近更新 更多