[英]Multiple image upload, resize and saveinto db using codeigniter
我正在嘗試使用codeigniter上傳多個圖像。 這是場景
如何上傳多張圖片並將圖片位置保存到db中(因為我想在視圖文件中顯示上傳的圖片),並且在上傳之前我還想重命名圖片並將其大小調整為“縮略圖”大小。
這是我的控制器:
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
}
}
}
我可以上傳多張圖片,但無法將其位置發送到我的數據庫中,也無法調整它們的大小。 請幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.