I am trying upload multiple file in a folder but it’s giving the error “You did not select a file to upload.”
A PHP Error was encountered
Severity: Warning
Message: is_uploaded_file() expects parameter 1 to be string, array given
Filename: libraries/Upload.php
Line Number: 412
Backtrace:
File: C:wampwwwmshaadiapplicationcontrollersEmail.php Line: 55 Function: do_upload
File: C:wampwwwmshaadiindex.php Line: 293 Function: require_once
Controller
$conf['upload_path'] = './images'; $conf['allowed_types'] = 'doc|docx|pdf|jpg|gif|jpeg|png'; $conf['max_size'] = '9999000'; $conf['max_width'] = '1024'; $conf['max_height'] = '768'; $conf['overwrite'] = TRUE; $this->load->library('upload'); foreach ($_FILES as $fieldname => $fileObject){ $this->upload->initialize($conf); if (!empty($fileObject['name'])){ if (!$this->upload->do_upload($fieldname)){ $error = $this->upload->display_errors(); print_r($error); }else{ print_r("done"); } }else { print_r("no"); } }
view
<div class="form-group col-md-12"> <label for="Attach"><strong>Add Attachment</strong><br></label> <input type="file" class="btn btn-default btn-file" name="atta[]" id="Attach" multiple="multiple"> </div>
Advertisement
Answer
Try like this,
function upload_files() { $config = array(); $config['upload_path'] = './Images/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '0'; $config['overwrite'] = FALSE; $this->load->library('upload'); $files = $_FILES; for($i=0; $i< count($_FILES['userfile']['name']); $i++) { $_FILES['userfile']['name']= $files['userfile']['name'][$i]; $_FILES['userfile']['type']= $files['userfile']['type'][$i]; $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i]; $_FILES['userfile']['error']= $files['userfile']['error'][$i]; $_FILES['userfile']['size']= $files['userfile']['size'][$i]; $this->upload->initialize($config); $this->upload->do_upload(); } }