2016-12-29 63 views
0

我已成功上传图像数据库。但是不能成功从数据库获取图像。 我想从数据库中获取图像。尝试从codeignitor中的数据库获取图像。

这里是我的代码, 控制器 - >的login.php

public function user_update(){ 


      $this->load->model('login_model'); 
      $this->form_validation->set_rules('fname', 'First Name','required'); 
      $this->form_validation->set_rules('lname', 'Last Name','required'); 
      $this->form_validation->set_rules('cnumber', 'Contact Number','required|min_length[10]|max_length[10]|numeric'); 

       $config['upload_path']   = './uploads/'; 
       $config['allowed_types']  = 'doc|docx|pdf|gif|jpg|png|xlsx'; 
       $config['max_size']    = 10000; 
       $config['max_width']   = 1024; 
       $config['max_height']   = 768; 

       $this->load->library('upload', $config); 
       if ((! $this->upload->do_upload('image')) && ($this->form_validation->run() === FALSE)) 
       { 


         $this->load->view('student/home'); 
       } 
       else 
       { 
         $data = array('upload_data' => $this->upload->data()); 
        $image_name=($data['upload_data']['file_name']); 
         $resume=base_url().$image_name; 

        $udata = array(
         'id' => $this->input->post('id'), 
         'fname' => $this->input->post('fname'), 
         'mname' => $this->input->post('mname'), 
         'lname' => $this->input->post('lname'), 
         'email' => $this->input->post('email'), 
         'address' => $this->input->post('address'), 
         'cnumber' => $this->input->post('cnumber'), 
         'image'=> $resume 
       ); 
       $this->login_model->Updateuser($udata); 
       } 
} 

模型文件: - login_model.php

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class login_model extends CI_Model 
{ 
function Updateuser($param) { 

     $id = $param['id']; 

     $usar1 = array(
      'Student_Name' => $param['fname'], 
      'm_name' => $param['mname'], 
      'l_name' => $param['lname'], 
      'Student_Email' => $param['email'], 
      'contact_no' => $param['cnumber'], 
      'Address' => $param['address'], 
      'image' => $param['image'] 

      ); 
     $this->db->where('Student_id', $id); 
     $this->db->update('students', $usar1); 
     //echo ($this->db->last_query()); 
     //exit(); 
     $sturesult = $this->login_model->get_student_list(); 
     $data['Stulist'] = $sturesult; 
     $this->load->view('student/default_list',$data); 

    } 
} 

视图文件: - edit_info.php

<div class="container" id='main-layout' style="border-top: 1px solid #D14B54; background: #f5f5f5f5"> 
    <div class="row"> 
     <div class="col-md-8 col-sm-8"> 
      <div class="ajaxResponse"><input type="hidden" name="ajaxResponse"></div> 
      <div class="row" style="padding: 10px 5px;"> 
       <?php $id = $this->uri->segment(3); if(!empty($id)): ?> 
       <div class=""> 
       <?php echo validation_errors(); 
       echo $lname; 
       ?> 

        <div class="thumbnail familycol" style="padding:16px"> 
          <?php echo form_open_multipart('login/user_update'); ?> 
          <legend>Personal Information</legend> 
          <div class="row"> 

           <?php //echo form_label('Id :'); ?> <?php echo form_error('id'); ?> 
           <input type="hidden" name="id" value="<?php echo $row->Student_id; ?>" class="form-control input-sm" placeholder="id"/> 
            <!-- <label class="required">First name</label>--> 



           <div class="col-xs-6 col-md-6"> 
           <label for="First Name">First Name:</label> 
            <input type="input" name="fname" class="form-control" value="<?php echo $row->Student_Name;?>"/><font color="red"><?php echo form_error('fname'); ?></font> 


           </div> 

           <div class="col-xs-6 col-md-6"> 

            <!--<label class="required">Middle name</label>--> 
            <label for="Last Name">Middle Name:</label> 
            <input type="input" name="mname" class="form-control" value="<?php echo $row->m_name?>"/><font color="red"><?php echo form_error('mname'); ?></font> 

           </div> 
           </div> 
           <div class="row"> 
           <div class="col-xs-6 col-md-6"> 
            <!--<label class="required">Last name</label>--> 
            <label for="Last Name">Last Name:</label> 
            <input type="input" name="lname" class="form-control" value="<?php echo $row->l_name ;?>"/><font color="red"><?php echo form_error('lname'); ?></font> 
           </div> 
           <div class="col-xs-6 col-md-6"> 
           <?php echo form_label('Email :'); ?> <?php echo form_error('email'); ?> 
            <input type="text" name="email" value="<?php echo $row->Student_Email; ?>" class="form-control input-sm" placeholder="Email" /> 
           </div> 
           </div> 
          <br> 
          <div class="row"> 
           <div class="col-sm-6"> 
           <!--<label>Address</label>--> 
            <label for="text">Address</label> 
            <textarea name="address" class="form-control"><?php echo $row->Address ;?></textarea><font color="red"><?php echo form_error('address'); ?></font> 
           </div> 
           <div class="col-sm-6"> 
            <label for="text">Contact Number</label> 

            <textarea name="cnumber" class="form-control"><?php echo $row->contact_no ;?></textarea><font color="red"><?php echo form_error('cnumber'); ?></font> 
           </div> 

           <br/> 
          </div> 
          <br/> 
           <label for='uploaded_file'>Select A File To Upload:</label> 
           <input type="file" name="image" accept="image/*" value="upload"> 

          <br/> 
          <button class="btn btn-lg btn-primary btn-block signup-btn" type="submit" style="margin-top: 5px;"> 
           Update my Profile</button> 

        </div> 
       </div> 

       <?php endif;?> 
      </div> 
     </div> 
    </div> 

</div> 

回答

0

Ok让代码在您的视图文件中:

<img src="<?php echo base_url('uploads/').$Stulist[$i]->image; ?>" 
0

您已更新数据库中上传图像的错误图像目录。

的代码

$data = array('upload_data' => $this->upload->data()); 
$image_name=($data['upload_data']['file_name']); 
$resume=base_url().$image_name; 

以下几行简单地更新到

$data = array('upload_data' => $this->upload->data()); 
$image_name=($data['upload_data']['file_name']); 
$resume=base_url('uploads').$image_name; 

这里BASE_URL指向您上传您的图片上传目录。

相关问题