0
나는 codeigniter를 사용하여 이미지 갤러리를 만들고 싶습니다. 하지만 my는 여러 이미지를 업로드 할 때 작동하지 않습니다. 지금, 내 코드는 단일 이미지 업로드를 위해 작업하고 데이터베이스에 저장합니다.Codeigniter 다중 이미지 업로드 및 데이터베이스에 저장
여기 내 컨트롤러의
function post()
{
$config = array(
array(
'field' => 'teknologi_title',
'label' => '*',
'rules' => 'required|min_length[5]'
),
array(
'field' => 'sub_title',
'label' => '*',
'rules' => 'required|min_length[5]'
),
array(
'field' => 'editor',
'label' => '*',
'rules' => 'required|min_length[5]'
)
);
$this->form_validation->set_error_delimiters('<div class="text-error">', '</div>');
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$data = array(
'teknologi_title' => $this->input->post("teknologi_title", TRUE) ,
'sub_title' => $this->input->post("sub_title", TRUE) ,
'description' => html_entity_decode($this->input->post("editor", TRUE)) ,
'create_at' => date('Y-m-d H:i:s')
);
$this->load->model('Teknologi_m');
$result=$this->Teknologi_m->insert($data);
if($result!==FALSE)
{
$log_task = array(
'user_id' => $_SESSION['admin_user']['id'],
'user_email' => $_SESSION['admin_user']['email'],
'task' => json_encode($data),
'url_task' => $_SERVER['REQUEST_URI'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
'ip_address' => $_SERVER['REMOTE_ADDR'],
'sdate' => date('Y-m-d H:i:s')
);
$this->master_lib->log_task($log_task);
if($_FILES['userfile']['error'] != 4)
{
$config['upload_path'] = './___userfiles/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['overwrite']=TRUE;
$config['file_type'] = 'image/jpeg';
$config['encrypt_name']=TRUE;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload())
{
$data=$this->upload->data();
$this->load->library("image_moo");
$this->image_moo->load($config['upload_path'].$data['file_name'])
->resize(160,160)
->save($config['upload_path'].$data['raw_name'].'_thumb'.$data['file_ext']);
$data = array(
'image_header' => $data['file_name'],
'image_thumb' => $data['raw_name'].'_thumb'.$data['file_ext']
);
$id = $this->Teknologi_m->get_id();
$this->Teknologi_m->update_photo($id,$data);
}
}
$this->session->set_flashdata('success', "Data has been saved");
redirect('teknologi');
}
else
{
$this->session->set_flashdata('error', 'There is an error save data failed');
redirect('teknologi/add');
}
}
}
여기 내 모델의 :
이function update_photo($id=false,$data=false)
{
$this->load->database();
$this->db->where('id',$id);
$this->db->update('teknologi',$data);
}