現在我正在嘗試用戶圖像(user_pic,background_image)upoload。 但我的代碼不起作用。 我應該做一些不同的事情嗎?不確定發生了什麼問題。如何在Codeigniter中上傳多張圖片?
這裏我的html代碼
<form action="<?=base_url();?>edit/up_profile/" method="post" enctype="multipart/form-data">
<input type="file" name="pic_file">
<input type="file" name="pic_bgfile" />
<button type="submit">
我的控制器代碼
if($this->form_validation->run() === false){
}else{
$config = array(
'upload_path' => "./images/u/photo",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000",
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload',$config);
if($this->upload->do_upload('pic_file')){
$data['profile_image'] = $this->upload->data();
}else if($this->upload->do_upload('pic_bgfile')){
$data['pic_bgfile'] = $this->upload->data();
}
$this->load->model('user_model');
$data = array(
'user_id' => $this->session->userdata('user_id'),
'info_tit' => $this->input->post('info_tit'),
'scope' => $this->input->post('scope')
);
$this->user_model->p_update($data);
//redirect
redirect('/edit/profile/', 'location', 301);
}
如果你想上傳笨僅僅是由上傳一次在一個圖像的多個圖像,但這種聯繫可能有助於http://stackoverflow.com/questions/11524356/multiple -files-upload-array-with-codeigniter-2-0 – user4419336
@ wolfgang1983 thx! – bothsa24312