0
基於CI文檔中的示例,我遇到了使用這種簡單的Codeigniter圖像上傳的問題。Codeigniter上傳不允許的文件不會產生錯誤
到底哪裏出問題了:
1)如果不正確的文件類型上傳,它不返回一個錯誤。它將我所有的post變量設置爲null,並繼續處理。
2.)我可以上傳.sql和一些(但不是全部).exe文件,甚至可以將允許的文件類型限制爲jpg,gif和png。
因此,它不是拒絕允許的文件類型的常見報告問題,而是過於寬容,並且在它應該時不返回錯誤。
$photo = $this->input->post("photo");
$config['upload_path'] = './profile_img/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if(isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0){
if (! $this->upload->do_upload('userfile'))
{
$error = $this->upload->display_errors();
$this->session->set_userdata("message", $error);
header("Location: /page/account");
}
else
{
$upload_data = $this->upload->data();
$photo = $upload_data['file_name'];
}
}
$data = array(
'first_name' => $this->input->post("first_name"),
'last_name' => $this->input->post("last_name"),
'username' => $this->input->post("username"),
'default_meeting_duration' => $this->input->post("default_meeting_duration"),
'notification_type' => $this->input->post("notification_type"),
'photo' => $photo
);
$this->user_model->update($data, $this->ion_auth->get_user_id());
$this->session->set_userdata("message", "Account Settings Saved");
header("Location: /page/account");
先刪除,如果條件再試試 –