CodeIgniter - uploading multiple files with one input

半世苍凉 提交于 2019-12-30 13:11:52

问题


I'm trying to upload several files at once from ONE input:

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

Which itself without CodeIgniter works fine. In my attempt to do the same thing with CodeIgniters file helper; I get an error (is_uploaded_file() expects parameter 1 to be string, array given), which indicates that I am doing something wrong, or CodeIgniter simply doesn't support multiple files?

My faulty code so far:

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

Please note that I did edit out all error handling and such. Also note that I do not use the is_uploaded_file() function.

Appreciating all help and suggestions. Thanks.


回答1:


CodeIgniter doesn't support multiple files. Using the do_upload() in a foreach won't be different than using it outside.

You will need to deal with it without the help of CodeIgniter. Here's an example https://github.com/woxxy/FoOlSlide/blob/master/application/controllers/admin/series.php#L331-370




回答2:


I'm using an extension of the Upload library that includes a do_multiple_upload() function accepting an array of files

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

It lacks some error management (e.g. if one of your files doesn't have an allowed extension the whole upload fails), but you can change the returns for continues in the loop.

Hope it helps somebody...



来源:https://stackoverflow.com/questions/9845872/codeigniter-uploading-multiple-files-with-one-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!