In this article, we'll delve into a query regarding multiple file upload using a single element in CodeIgniter. By evaluating the provided form, controller, file upload method, and the encountered issue, we'll dissect and resolve this issue to provide a comprehensive solution.
The initial issue stemmed from the file upload method not aligning correctly with the incoming file input. The adjustment proposed by @Denmark aptly rectified this discrepancy by reassigning the form input name from "images" to "images[]" to match the multiple file selection.
private function upload_files($path, $title, $files) { $config = array( 'upload_path' => $path, 'allowed_types' => 'jpg|gif|png', 'overwrite' => 1, ); $this->load->library('upload', $config); $images = array(); foreach ($files['name'] as $key => $image) { $_FILES['images[]']['name']= $files['name'][$key]; $_FILES['images[]']['type']= $files['type'][$key]; $_FILES['images[]']['tmp_name']= $files['tmp_name'][$key]; $_FILES['images[]']['error']= $files['error'][$key]; $_FILES['images[]']['size']= $files['size'][$key]; $fileName = $title . '_' . $image; $images[] = $fileName; $config['file_name'] = $fileName; $this->upload->initialize($config); if ($this->upload->do_upload('images[]')) { $this->upload->data(); } else { return false; } } return $images; }
By following this revised method, you can successfully upload multiple files using a single input element in CodeIgniter.
The above is the detailed content of How to Achieve Multiple File Uploads in CodeIgniter Using a Single Input Field?. For more information, please follow other related articles on the PHP Chinese website!