0

I have been trying to upload multiple images using codeigniter file uploading library. Everything is working except it's not saving the images in directory, I have check permissions everything is perfect. I have also tried changing package but still face same issue.

This is my code for uploading.

   $count = count($_FILES['upload_' . $increment]['size']);

   for ($s = 0; $s <= $count-1; $s++) {
     $config['upload_path']   = './uploads/';
     $config['allowed_types'] = 'gif|jpg|png|jpeg';
     $config['max_size']      = '10000';
     $config['max_width']     = '2048';
     $config['max_height']    = '1152';

     $image = $config['file_name'] = $c_id . '-' . $s . '.jpg';

     $this->load->library('upload', $config);
     $this->upload->initialize($config);
     $this->upload->do_upload();

     $data = $this->upload->data();
     $data = array('c_id' => $c_id, 'image'=> $image);

     $this->db->insert('images', $data);
   }

   $increment++;
makallio85
  • 1,366
  • 2
  • 14
  • 29

2 Answers2

0

Are you using html form action for submit the data?

If yes, please add enctype="multipart/form-data" into your form tag as:

<form action="your action url" method="post" enctype="multipart/form-data">
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
0

Try this Downlaod this Codeigniter Library and put this file under application/libraries

Controller

if ($_FILES) {
    $config['upload_path']   = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']      = '200';
    $config['max_width']     = '1024';
    $config['max_height']    = '768';
    $this->load->library('upload');
    $this->upload->initialize($config);
    if (!$this->upload->do_multi_upload("file")) {
        $data['errors'] = ($this->upload->display_errors());
    } else {
        $images = ($this->upload->get_multi_upload_data());
        for ($i = 0; $i < count($images); $i++) {
        $this->user_model->addUserImage($images[$i]);
        }
    }

Model

public function addUserImage($image)
{
  $image_data=array(
    'name'=>$image['file_name']
  );
   $this->db->insert('user_images',$image_data);
   return true;
}

Let me if any query here

Muhammad Usman
  • 1,403
  • 13
  • 24