[英]Multiple image upload, resize and saveinto db using codeigniter
I am trying to upload multiple image using codeigniter. 我正在尝试使用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. 如何上传多张图片并将图片位置保存到db中(因为我想在视图文件中显示上传的图片),并且在上传之前我还想重命名图片并将其大小调整为“缩略图”大小。
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'];
看起来您的
$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']
. 您还应该在
$config['new_image']
。
And if you want to upload the data to your database, you could probably create a model which handles that operation. 如果要将数据上传到数据库,则可以创建一个处理该操作的模型 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.