没有个人资料图片,数据更新无效

时间:2015-12-09 06:50:21

标签: php codeigniter

在php中,当我使用个人资料图像将用户信息更新到数据库中时,更新正在运行,但是当我没有选择图像时,更新无效。

这是我的控制器:

public function editvendor($id = '') {
    $this->authAdLogin();

    if ($id == '') {

        redirect(admin_url() . 'vendorlisting');
    } else if ($this->db->where('id', $id)->get('tbl_vendor')->num_rows() == 0) {
        redirect(admin_url() . 'vendorlisting');
    } else {

        $data['vendor_data'] = $this->db->where('id', $id)->get('tbl_vendor')->result_array();
        $vendor_data = $data['vendor_data'];

        $this->form_validation->set_rules('contact_name', 'Name', 'trim|xss_clean|required');
        $this->form_validation->set_rules('contact_mobile', 'Mobile Number', 'trim|xss_clean|required|numericmin_length[10]|max_length[10]');

        $this->form_validation->set_rules('contact_land', 'Landline Number', 'trim|xss_clean|numeric');
        $this->form_validation->set_rules('contact_email', 'Email', 'trim|xss_clean|required|valid_email');
        $this->form_validation->set_rules('incorporation_date', 'Incorporation Date', 'trim|xss_clean|required');
        $this->form_validation->set_rules('pancard_no', 'Pan Card', 'trim|xss_clean|required');
        $this->form_validation->set_rules('tan_no', 'Tan Number', 'trim|xss_clean|required');
        $this->form_validation->set_rules('tin_no', 'Tin Number', 'trim|xss_clean|required');
        $this->form_validation->set_rules('service_no', 'Service Number', 'trim|xss_clean|required');



        if ($this->form_validation->run() == false) {

            $this->load->view('admin/header');
            $this->load->view('admin/sidemenu');
            $this->load->view('admin/editvendor', $data);
        } else {

            $id = $vendor_data[0]['id'];
            $upload_dir = './uploads/' . $vendor_data[0]['vendor_id'];
            if (!is_dir($upload_dir)) {
                mkdir($upload_dir);
            }
            if (isset($_FILES['profile_pic']['name'])) {


                $config['upload_path'] = './uploads/' . $vendor_data[0]['vendor_id'];
                $config['allowed_types'] = 'gif|jpg|png';
                /* $config['max_size']   = '1000000';
                  $config['max_width']  = '10240000';
                  $config['max_height']  = '7680000'; */
                $config['file_name'] = "prof_" . rand(1, 5000);

                $this->load->library('upload');

                $this->upload->initialize($config);

                if (!$this->upload->do_upload('profile_pic')) {
                    $error = $this->upload->display_errors();

                    $this->session->set_flashdata('ppic_error', $error);


                    redirect(admin_url() . 'editvendor');
                } else {
                    $data = $this->upload->data();
                    $prof_pic = $data['file_name'];
                }
            } else {


                $prof_pic = $vendor_data[0]['profile_pic'];
            }


            $update_data = array(
                'contact_name' => $this->input->post('contact_name'),
                'contact_mobile' => $this->input->post('contact_mobile'),
                'contact_land' => $this->input->post('contact_land'),
                'contact_email' => $this->input->post('contact_email'),
                'mailing_address' => $this->input->post('mailing_address'),
                'incorporation_date' => $this->input->post('incorporation_date'),
                'pancard_no' => $this->input->post('pancard_no'),
                'tan_no' => $this->input->post('mailing_address'),
                'mailing_address' => $this->input->post('tan_no'),
                'tin_no' => $this->input->post('tin_no'),
                'service_no' => $this->input->post('service_no'),
                'web_url' => $this->input->post('web_url'),
                'business_address' => $this->input->post('business_address'),
                'other_certificates' => $this->input->post('other_certificates'),
                'facebook_link' => $this->input->post('facebook_link'),
                'twitter_link' => $this->input->post('twitter_link'),
                'linkedin_link' => $this->input->post('linkedin_link'),
                'googleplus_link' => $this->input->post('googleplus_link'),
                'about_company' => $this->input->post('about_company'),
                'industry_segment' => $this->input->post('industry_segment'),
                'ayurveda' => $this->input->post('ayurveda'),
                'homeopathy' => $this->input->post('homeopathy'),
                'unani' => $this->input->post('unani'),
                'profile_pic' => $prof_pic,
            );

            $this->db->where('id', $id);
            $this->db->update('tbl_vendor', $update_data);

            $this->session->set_flashdata('vendor_edit', 'Successfully updated.');

            redirect(admin_url() . 'editvendor/' . $id);
        }
    }
}

请 提供任何解决方案。

0 个答案:

没有答案