Virajsinh

Multiple File Upload in CodeIgniter 3

Aug 26th, 2020
951
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if($images['name'][$i] != ''){
  2.     $name = explode('.', $images['name'][$i]);
  3.     $filename = time().rand(1000,9999).'.'.end($name);
  4.  
  5.     $config = array(
  6.               'upload_path'     => "assets/uploaded/property/",
  7.               'upload_url'      => base_url()."assets/uploaded/property/",
  8.               'allowed_types'   => 'jpeg|jpg|png',
  9.               'max_size'        => '1024',
  10.               'file_name'       => $filename,
  11.               'overwrite'       => FALSE
  12.             );
  13.  
  14.     $_FILES['image']['name'] = $_FILES['images']['name'][$i];
  15.     $_FILES['image']['type'] = $_FILES['images']['type'][$i];
  16.     $_FILES['image']['tmp_name'] = $_FILES['images']['tmp_name'][$i];
  17.     $_FILES['image']['error'] = $_FILES['images']['error'][$i];
  18.     $_FILES['image']['size'] = $_FILES['images']['size'][$i];
  19.  
  20.     $this->upload->initialize($config);
  21.     if(!$this->upload->do_upload('image'))
  22.     {
  23.         echo $this->upload->display_errors();
  24.         $data['type'] = 'Error';
  25.         $data['message'] = 'Uploaded file is not a valid image. Only JPG, JPEG and PNG files are allowed.';
  26.         echo json_encode($data);
  27.         exit;
  28.     }else{
  29.         $this->upload->data();
  30.     }
  31. }
RAW Paste Data