我有一个问题,我花了我 2 个小时,但我无法解决它。
当我想上传多张图片(3张图片)时,它会上传,但我无法为所有人创建拇指,只为第一张图片,我不知道问题出在哪里
这是我的表格
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="hotel_img1" value="upload" name="hotel_img1">
<input type="file" id="hotel_img2" value="upload" name="hotel_img1">
<input type="file" id="hotel_img3" value="upload" name="hotel_img1">
<input type="submit">
</form>
这是我的代码控制器
<?php
if(!empty($_FILES))
$upload_image = array('1','2','3','4','5');
foreach($upload_image as $i) {
if(!empty($_FILES["hotel_img$i"]['name']))
{
$hotel_ID= 12;
$config['file_name'] = $this->session->userdata('user_id').'-'.$hotel_ID.'-'.time().$i;
$config['upload_path'] =realpath(APPPATH . '../img');
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '512';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['overwrite'] = TRUE;
$this->upload->initialize($config);
$form_name = 'hotel_img' . $i;
if(!$this->upload->do_upload($form_name))
{
$data['msg'] .= "ERROR";
}
else
{
$file_data = $this->upload->data();
$image_data['img_url'] = $file_data['file_name'];
$image_data['img_size'] = $file_data['file_size'] * 1024;
$image_data['img_forID'] = $hotel_ID;
$this->model_hotels->insert_image($image_data);
$data['msg'] .= "Uploaded Picture No $i";
$config_thumb['image_library'] = 'gd2';
$config_thumb['source_image'] = $file_data['full_path'];
$config_thumb['maintain_ratio'] = FALSE;
$config_thumb['width'] = 250;
$config_thumb['height'] = 150;
$config_thumb['new_image'] = realpath(APPPATH . '../img').'/thumb/thumb_' . $file_data['file_name'];
$this->load->library('image_lib', $config_thumb);
$this->image_lib->resize();
$this->image_lib->clear();
}
}
}
$this->model_hotels->set_hotel_thumb($hotel_ID);
} ?>