【发布时间】:2019-02-17 23:39:05
【问题描述】:
我正在开发一个 codeigniter 项目。在图像上传配置中,我将其加密以允许唯一的文件名,以避免覆盖和名称加倍,并提高一般安全性。
所以在上传时它将加密图像文件名,并将加密的名称存储在数据库中,同时将图像保存在我的资产文件夹中。但由于某种原因,它似乎根本没有加密图像名称。几乎就像它完全忽略了$config 选项而只是上传图像。
我还尝试了一个回调函数来避免空白上传,并且似乎也被忽略了并且仍然允许发布。
如果有人可以给小费。请。
控制器
//Callback validation
$this->form_validation->set_rules('userfile','Photo','callback_photo_check');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('posts/create', $data);
$this->load->view('templates/footer');
} else {
if($this->form_validation->run()==TRUE){
$config['upload_path'] = 'assets/images/posts';
$config['allowed_types'] = 'gif|jpg|jpeg';
$config['encrypt_name'] = TRUE; //TURN ON
$config['max_size'] = 0;
$config['max_width'] = 0;
$config['max_height'] = 0;
$this->upload->initialize($config);
if(!$this->upload->do_upload('userfile')){
$errors = array('error'=>$this->upload->display_errors());
$this->load->view('templates/header');
$this->load->view('posts/create', $errors);
$this->load->view('templates/footer');
}else {
$this->post_model->create_post($this->upload->data('full_path'),$this->input->post());
}
}
$this->session->set_flashdata('post_created','Your Post has been submitted');
redirect('posts');
}
}
public function photo_check(){
if(empty($_FILES['userfile'])){
$this->form_validation->set_message('photo_check', 'need a image');
return FALSE;
}
else{
return TRUE;
}
}
型号
public function create_post($path,$post){
$data = array(
'about'=> $this->input->post('Description'),
'image' => $path,
);
return $this->db->insert('posts',$data);
【问题讨论】:
-
你是如何设置config['overwrite']的?
-
我没有为它设置值,因为默认布尔值是 FALSE。
-
@PHPNoob 请参考下面我的回答。 stackoverflow.com/questions/54738739/…
标签: php codeigniter codeigniter-3