我有一張表單,可以上傳3張圖片。 在codeigniter中,我做了一個foreach循環來處理圖像,並將它們保存到我的數據庫中。這很好。在codeigniter中上傳多個文件並調整大小
但我需要調整圖像大小。當我上傳一個圖像時,調整大小的作品,但有更多的圖像,第一個圖像看起來像狗屎,第二個和第三個圖像不會調整大小......你們可以幫我嗎?
$this->load->library('upload');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['encrypt_name'] = TRUE;
//$config['overwrite'] = TRUE;
$this->upload->initialize($config);
$count = 0;
foreach($_FILES as $field => $file)
{
$count = $count + 1;
// No problems with the file
if($file['error'] == 0)
{
// So lets upload
if ($this->upload->do_upload($field))
{
$data = $this->upload->data();
$data2 = array(
'image' . $count => $data['file_name']
);
$this->db->where('id', $query_id);
$this->db->update('ads', $data2);
//afbeeldingen verkleinen.
$config['image_library'] = 'gd2';
$config['source_image'] = $data['full_path'];
//$config['new_image'] = './image_uploads/';
$config['maintain_ratio'] = TRUE;
$config['width'] = 370;
$config['height'] = 277;
$this->load->library('image_lib',$config);
if (!$this->image_lib->resize()){
$this->session->set_flashdata('errors', $this->image_lib->display_errors('', ''));
echo $this->image_lib->display_errors('', '');
exit();
}
}
else
{
$errors = $this->upload->display_errors();
echo $errors;
exit();
}
}
}
$data['name'] = $name;
redirect('/adDetail/getDetails/' . $query_id, 'location', 200);
}
嘗試重置'$ config'變量 –