In codeigniter upload multiple image.

public function image(){
$files = $_FILES;
$cpt = count($_FILES[‘userfile’][‘name’]);
for($i=0; $i<$cpt; $i++)
{
$_FILES[‘userfile’][‘name’]= time().$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($this->set_upload_options());
$this->upload->do_upload();
$fileName = $_FILES[‘userfile’][‘name’];
$images[] = $fileName;
}
$image = implode(‘,’,$images);
$this->image_model->addimages($image);
}

 

Upload an image options

public function set_upload_options()
{
$config = array();
$config[‘upload_path’] = ‘assets/upload/package/’; //give the path to upload the image in folder
$config[‘allowed_types’] = ‘gif|jpg|jpeg|png’;
$config[‘max_size’] = ‘0’;
$config[‘overwrite’] = FALSE;
return $config;
}

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *

PAGE TOP
error

Enjoy this blog? Please spread the word :)

RSS
Follow by Email