【发布时间】:2018-11-24 03:41:20
【问题描述】:
问题是如何同时验证图像和表单数据
$this->load->library('form_validation');
$this->form_validation->set_message('file_check', 'jpg attachement allowed Only');
$this->form_validation->set_rules('file', '', 'callback_file_check');
$this->form_validation->set_rules('number','Number','trim|required|min_length[10]|max_length[10]');
if($this->form_validation->run()){
$name=$this->input->post('name');
$subject=$this->input->post('subject');
$messege=$this->input->post('messege');
$number=$this->input->post('number');
$configs['upload_path'] = './uploads/';
$configs['allowed_types'] = 'jpg';
$this->load->library('upload', $configs);
//upload file to directory
if($this->upload->do_upload('file') ){
$upload_data = $this->upload->data();
$this->load->library('email',$config);
$this->email->attach($upload_data['full_path']);
$this->email->set_newline("\r\n");
$email_body ="<div >".$messege."</div>";
$this->email->set_mailtype("html");
$this->email->from('mail@gmail.com',$name);
$this->email->to('mailto@gmail.com');
$this->email->subject($subject);
$this->email->message($email_body);
$this->email->send();
$this->index();
}
}
【问题讨论】:
标签: php codeigniter validation file-upload