0
私はcodeIgniterが新しく、私はフォームにサインアップし、プロフィール画像をアップロードしてデータベースに画像名を保存しようとしています。 form_open
私はform_open_multipart
の画像アップロードを使用してもクエリはnullに設定され、すべての操作が失敗するため、ファイルはデータベースに保存されますが、データベースに保存されません。codeIgniter uplaod image failer
<?php
class User extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->helper('url_helper');
$this->load->model('user_model');
$this->load->helper('form');
$this->load->helper('date');
$this->load->library('form_validation');
}
public function sign_up(){
$this->form_validation->set_rules('name', 'Username', 'trim|required|min_length[3]|max_length[20]');
$data['title']='Sign Up Page';
$config = array(
array(
'field'=>'email',
'label'=>'Email',
'rules'=>'required'
),
array(
'field'=>'mobile',
'label'=>'Mobile',
'rules'=>'required'
),
array(
'field'=>'flat_number',
'label'=>'flat number',
'rules'=>'required'
),
array(
'field'=>'street_number',
'label'=>'street number',
'rules'=>'required'
),
array(
'field'=>'street',
'label'=>'street',
'rules'=>'required'
),
array(
'field'=>'area',
'label'=>'area',
'rules'=>'required'
),
array(
'field'=>'governor',
'label'=>'governor',
'rules'=>'required'
),
array(
'field'=>'name',
'label'=>'Name',
'rules'=>'required'
),
array(
'field'=>'birth_day',
'label'=>'birth day',
'rules'=>'required'
),
array(
'field'=>'birth_month',
'label'=>'birth month',
'rules'=>'required'
),
array(
'field'=>'birth_year',
'label'=>'birth year',
'rules'=>'required'
),
array(
'field'=>'gender',
'label'=>'gender',
'rules'=>'required'
),
array(
'field'=>'user_type',
'label'=>'user type',
'rules'=>'required'
),
);
$this->form_validation->set_rules($config);
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('password_comfirm', 'Password Confirmation', 'required|matches[password]');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
$config['max_width'] = 1024;
$config['max_height'] = 1024;
$this->load->library('upload', $config);
$this->upload->do_upload('profile_pic');
if($this->form_validation->run() === false){
$this->load->view('user/sign_up',$data);
}
else{
$data = array('upload_data' => $this->upload->data());
$this->user_model->add_user();
$this->load->view('main_pages/succes');
}
}
}
<?php
クラスUser_model拡張CI_Model {
public function __construct(){
$this->load->database();
}
public function add_user(){
$datestring = '%d-%m-%Y';
$time = time();
$sign_up_date = mdate($datestring, $time);
$address = $this->input->post('flat_number').'-'.$this->input->post('street_number').'-'.$this->input->post('street').'-'.$this->input->post('area');
$birthdate = $this->input->post('birth_day').'-'.$this->input->post('birth_month').'-'.$this->input->post('birth_year');
$data = array(
'name' => $this->input->post('name'),
'sign_up_date' => $sign_up_date,
'email' => $this->input->post('email'),
'mobile' => $this->input->post('mobile'),
'address' => $address,
'password' => $this->input->post('password'),
'birthdate' => $birthdate,
'gender' => $this->input->post('gender'),
'user_type' => $this->input->post('user_type'),
'pic_name' => $this->input->post('profile_pic'),
'governor' => $this->input->post('governor')
);
return $this->db->insert('user',$data);
}
}