Php 使用codeigniter将多个图像上载、调整大小并保存到db中
我正在尝试使用codeigniter上传多个图像。下面是一个场景 如何上载多个图像并将图像位置保存到db中(因为我想在视图文件中显示上载的图像),在上载之前,我还想重命名图像并将其调整为“拇指”大小 这是我的控制器:Php 使用codeigniter将多个图像上载、调整大小并保存到db中,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,我正在尝试使用codeigniter上传多个图像。下面是一个场景 如何上载多个图像并将图像位置保存到db中(因为我想在视图文件中显示上载的图像),在上载之前,我还想重命名图像并将其调整为“拇指”大小 这是我的控制器: function uploadRoomImage(){ $i = 0; $files = array(); foreach ($_FILES as $key => $value) { if(!empty($value['na
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
}
}
}
我可以上传多张图片,但我无法将它们的位置发送到我的数据库中,也无法调整它们的大小。plz help它看起来像是您的
$config['source\u image']=$image\u data['full\u path']代码>忽略附加到完整路径的文件名。您还应该在$config['new_image']
中包含这些内容
如果您想将数据上传到数据库,您可能需要由谁来处理该操作。首先从用户那里获取所有文件并将其存储在临时文件夹中。然后,您可以逐个调整它们的大小,并将它们移动到所需的文件夹位置。移动完成后,您可以将移动文件夹的路径保存到数据库中。@justrohu我已经编辑了我的代码,请看一看,现在我可以上传多个图像,但我无法将它们的位置发送到数据库中,也无法调整它们的大小。