I'm trying to upload multiple images using the codeigniter file upload library but it only uploads one file even when multiple are selected. Kindly assist
//uploading images
public function upload_image() {
$this->load->helper('form');
$config = array(
'upload_path' => "./image_uploads/",
'allowed_types' => "jpg|png|jpeg",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
var_dump($_FILES); die();
foreach ($_FILES as $key => $userfileObject) {
if (!empty($userfileObject['name'])) {
$this->upload->initialize($config);
var_dump($_FILES['userfile']);
if (!$this->upload->do_upload($_FILES[$key])) {
$errors = $this->upload->display_errors();
flashMsg($errors);
} else {
// Code After Files Upload Success GOES HERE
$data['content'] = 'success';
$this->load->view('templates/template', $data);
}`enter code here`
}
}
}
this might help where p_image
is file name
if (isset($_FILES['p_image']['name'])) {
// total files //
$count = count($_FILES['p_image']['name']);
// all uploads //
$uploads = $_FILES['p_image'];
for ($i = 0; $i < $count; $i++) {
if ($uploads['error'][$i] == 0) {
move_uploaded_file($uploads['tmp_name'][$i], 'uploads/product_cover/' . $uploads['name'][$i]);
}
}
}
foreach($_FILES as $key => $userfileObject)
{
if ($this->upload->do_upload($key))
{
$errors = $this->upload->display_errors();
flashMsg($errors);
}
else {
// Code After Files Upload Success GOES HERE
$data['content'] = 'success';
$this->load->view('templates/template', $data);
}`enter code here`
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.