我想在不刷新 codeigniter 页面的情况下上传带有名字和姓氏的图像

I want to upload an image with first name and last name without refreshing the page in codeigniter

This is my controller


 function edit_profile() {
        // if (isset($_POST['submit']))
        //{

        $session_data = $this->session->userdata('logged_in');
        $id = $session_data['id'];
        $name = $session_data['name'];




          $uploaddata = null;
                $config['upload_path'] = './assets/uploads/userpic';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '10000';
          $Img_name=  strtotime(date("d-m-y H:i:s")).".jpg";
            //$Img_name=  strtotime(date("d-m-y H:i:s"));

              $config['file_name']=    $Img_name ;
                $config['overwrite'] = "true";
                $this->load->library('upload', $config);


                if (!$this->upload->do_upload('documents')) {
                    $error = array('error' => $this->upload->display_errors());
                } else {
                    $uploaddata = array('upload_data' => $this->upload->data());



                }
         $upload_data = $this->upload->data(); 
          $file_name =   $name;
           $filepath1= $config['upload_path'];

     if(!is_uploaded_file($_FILES['documents']['tmp_name'])) {
    echo 'No upload';
      $data = array(
            'name' => $this->input->post('firstname'),
            'lname' => $this->input->post('lastname')
              );
}else
{
    echo "file uploaded";

        $data = array(
            'name' => $this->input->post('firstname'),
            'lname' => $this->input->post('lastname'),
            'filepath'=> $Img_name,
            'filename'=>$file_name
        );
}     
        $this->load->model('update_model');
        $this->update_model->update_entry($id, $data); //passing control to update_model
        $session_data['name'] = $this->input->post('firstname');
        $this->session->set_userdata('logged_in', $session_data); //settting sesssin values


         if( $data)
                    {
                    $data['message']="Image Uploaded Successfully";
                    $this->load->view('endusers/endemp_edit_profile_view',$data);
                    }
        //redirect('endusers/end_emp_home');
        //}
    }

这是我的看法

            <?php echo form_open_multipart('endusers/editprofile/edit_profile');?>
                <table width="auto" border="1" style="border-color: #bce8f1;"class="table table-bordered"  >
                    <tbody>



            <tr>
                                    <td colspan="2"><input type="text"  class="txt-field uname" name="firstname"  placeholder="first name" required></td>
            </tr>
                                <! ------ <tr>
                <td colspan="2"><input type="text" class="txt-field pass"  name="lastname"  placeholder="last name" required ></td><br>
            </tr> 

            <tr>

                     <tr>

                            <td valign="top">

                                     <label for="curtexp" style="margin-top: 20px;padding-right: 7px;margin-left: 11px;"> Upload a Profile Picture </label>&nbsp;<label class="error" ></label> 

                                <input type="file" name="documents" size="40" / style="margin-left: 9px;" placeholder="Profile Picture"><br><br>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="8" style="text-align:center">
                                <br />
                                <div class="ee">
                                    <input type="submit" class="btn btn-primary" value="Update" class="buttonmy2" / style="float: left;    margin-bottom: 17px;"> 

                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="Reset" class="btn btn-primary" value="Reset" class="buttonmy2" / style="float: left;margin-left: 10px;"> 
                                    <?php echo validation_errors(); ?>
                                </div>
                            </td> 
                        </tr>
                    </tbody>
                </table>
            </form> 

这是我在 codeigniter 中用于上传个人资料图片的代码,但它需要我注销才能看到上传的图片。我想让汤姆在不注销我的帐户的情况下上传图片,可能只是刷新页面

--这个Jquery插件会解决你的问题 --更多帮助http://malsup.com/jquery/form/#getting-started

<script src="http://malsup.github.com/jquery.form.js"></script> 


$("#form_id").on('submit', (function (e) {
    var options = { 
            url:'your URL',   // target element(s) to be updated with server response 
            success:function(data){
                 alert('submitted');
            }    
           $(this).ajaxSubmit(options); 
           e.preventDefault();
}));

如有需要请给我留言...