上传图像文件的问题

时间:2016-07-12 11:43:33

标签: php codeigniter

这是我的视图文件,其中存在图像和其他数据的表单:



    <?php echo form_open_multipart('Login/client_profile'); ?>
                        <div class="form-group">
                            <label>Company Name</label>
                            <input type="text" class="form-control" name="company_name"  >
                        </div>
                         
                        <div class="form-group">
                            <label>Upload Profile Picture</label>
               				<input type="file" name="profile_pic" accept="image/*" class="form-control"  required>
                        </div>
                        <div class="form-group">
                            <label>Mobile Number</label>
                            <input type="number" class="form-control" name="mobile"  required>
                        </div>
                        <div class="form-group">
                            <label>Specialist in</label>
                            <input type="text" class="form-control" name="specialist_in" >
                        </div>

                        <div class="form-group">
                            <label>Position</label>
                            <input type="text" class="form-control" name="position"  >
                        </div>

                         
                         <?php

                        $data7 = array(
                            'type'        => 'submit',
                            'value'       => 'Update',
                            'class'       => 'btn btn-primary ',
                        );
                        echo form_submit($data7);
                        echo form_close();
                       ?>
&#13;
&#13;
&#13;

这是控制器文件Client.php

&#13;
&#13;
     public function client_profile()
     {
	 $client=$this->input->post();
	 $client['profile_pic']=$this->input->post('profile_pic');
	 $this->load->model('Clientmodel');
	 $email=$this->session->userdata('email_id');
	 $this->Clientmodel->add_client_details($email,$client);
	 $ppic['pic']=$this->Clientmodel->get_pic($email);
                $config['upload_path'] = './profile/';
                $config['allowed_types'] = 'jpg|jif|png|jpeg';
                
                $this->load->library('upload', $config);
                $field = 'pic';
	            if ($this->upload->do_upload($field)) {
                    $temp = $this->upload->data();
                    $pic = $temp['file_name'];

                   
                }
		$this->load->view('client/pro_header',$ppic);
        $this->load->view('client/client_dashboard',$client);

 }
&#13;
&#13;
&#13;

这是模型文件Clientmodel.php

&#13;
&#13;
   public function add_client_details($email, Array $client)
	{
		 
		return $this->db->where(['email'=>$email])
		                ->update('clients',$client);
	}

   public function get_pic($login_email)
	{
		$q=$this->db->where(['email'=>$login_email])
		            ->get('clients');
		return $q->row()->profile_pic;
	}
&#13;
&#13;
&#13;

输入所有数据后,当我尝试获取$this->input->post时,可以使用'profile_pic'获取除image之外的所有字段,但它不返回任何内容。图像文件名也未插入database.Field表'profile_pic'

中有'clients'

1 个答案:

答案 0 :(得分:0)

这是用于上传它未检查任何验证

    public function upload_docs () {
        if($this->input->post('action') == 'Upload') {
            $company_name = $input->post('company_name');
            $position = $input->post('position');
            $mobile = $input->post('mobile');
            $specialist_in = $input->post('specialist_in');

            // capture all your variable like this

            $file_path = './assets/images/uploads';

             if ($_FILES["profile_pic"]["error"] > 0) {
                 $data['msg'] = 'your message';
             } else {
                 if(!is_dir($file_path)) @mkdir($file_path, 0777, true); 

                 if (move_uploaded_file($_FILES['profile_pic']['tmp_name'], $file_path.'/'.$_FILES['profile_pic']['name'])) {
                        $upload_data = array('company_name'=> $company_name,'mobile'=> $mobile,'specialist_in'=> $specialist_in,'profile_pic' => $_FILES['profile_pic']['name']);
                        $insert_id = $this->Your_model->addRecord($upload_data);
                        if ($insert_id) {           
                        //  redirect('admin/index','refresh');
                        } 
                 }
             }
        }

        $data['title'] = 'upload';

        $this->load->view('admin/upload',$data);

}