我遇到了問題,我花了2個小時,但無法解決問題。通過codeigniter上傳多張圖片並創建縮略圖
當我要上傳多張圖片(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);
} ?>
不,我的print_r($ file_data)是指出錯誤..感謝Mr.bananenspin^_ ^ – bosami