我正在尝试使用codeigniter上传多个图片。这是场景
我如何上传多个图像并将图像位置保存到数据库中(因为我想在我的视图文件中显示上传的图像),在上传之前我还想重命名我的图像并将它们调整为大拇指'大小
这是我的控制器:
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
}
}
}
我可以上传多张图片,但我无法将他们的位置发送到我的数据库中,我也无法调整它们的大小。请帮忙
答案 0 :(得分:0)
看起来您的$config['source_image'] = $image_data['full_path'];
错过了附加到完整路径的文件名。您还应该为$config['new_image']
添加该内容。
如果您想将数据上传到数据库,可能会create a model处理该操作。