I am trying to upload multiple image using codeigniter. here is the scenario
How can i upload multiple image and save image location into db (cause i want to show uploaded image in my view file) and before upload I also want to rename my images and resize them into 'thumb' size.
here is my controller:
function uploadRoomImage(){
$i = 0;
$files = array();
foreach ($_FILES as $key => $value) {
if(!empty($value['name']))
{
$config['upload_path'] = 'assets/img/upload/rooms/';
$config['allowed_types'] = 'jpg|jpeg';
$config['file_name'] = $filename;
$config['max_size'] = '2000';
$config['remove_spaces'] = true;
$config['overwrite'] = false;
$this->upload->initialize($config);
if (!$this->upload->do_upload($key))
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$files[$i] = $this->upload->data();
$i++;
//load image library
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $image_data['full_path'];
$config['new_image'] = $image_data['file_path'].'room_thumb/';
$config['maintain_ratio'] = FALSE;
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = '_thumb';
// $config['overwrite'] = false;
$config['width'] = 280;
$config['height'] = 280;
//initialize upload library using the config settings defined above.
$this->image_lib->initialize($config);
if (!$this->image_lib->resize()) {
$error = array('error' => $this->image_lib->display_errors());
} else {
$this->image_lib->resize();
}
//i want send each image file location into db in here after resizing each image
}
}
}
i can upload multiple image but i cann't send their location into my db and i cannt resize them also. plz help
It looks like your $config['source_image'] = $image_data['full_path'];
misses the file name attached to the full path. You should also include that for the $config['new_image']
.
And if you want to upload the data to your database, you could probably create a model which handles that operation.
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.