I have a view where the user can edit his details.
View
<form class="form-horizontal" method ="post" action="<?php echo site_url('studentDashboardController/saveUserDetails');?>">
<?php echo form_open('studentDashboardController/saveUserDetails'); ?>
<?php echo $this->session->flashdata('msg'); ?>
<fieldset>
<!-- Form Name -->
<legend>User Details</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Full Name</label>
<div class="col-md-8">
<input id="name" name="name" type="text" class="form-control input-md" value="<?php foreach($details as $detail){?><?php echo $detail->name?><?php }?>">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="dob">Date of Birth</label>
<div class="col-md-8">
<input id="dob" name="dob" type="text" placeholder="" class="form-control input-md" value="">
</div>
</div>
...
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="userfile">Upload Profile Picture</label>
<div class="col-md-4">
<input id="userfile" name="userfile" class="input-file" type="file">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" name="submit" type="submit" class="btn btn-primary">Save Changes</button>
</div>
</div>
Controller
public function saveUserDetails()
{
if (isset($this->session->userdata['logged_in']))
{
$uid = ($this->session->userdata['logged_in']['userId']);
$data['notifyCount']= $this->notifications->getUnreadNotification($uid);
$data['title']= $this->notifications->getUnreadNotificationTitle($uid);
$data['notifyCount']= $this->notifications->getUnreadNotification($uid);
$data['users'] = $this->user->getUserNames();
$config['upload_path'] = './assets/img/taro/profilePictures/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width'] = '5000';
$config['max_height'] = '3000';
$this->load->library('upload', $config);
$this->upload->do_upload();
$upload_data = $this->upload->data();
$msg = $this->studentprofileModel->saveUserDetails($uid,$this->input->post());
$msgText = $msg['msg'];
$msgType = $msg['type'];
//Loading View
if($msgType == "danger")
{
$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">'.$msgText.'</div>');
}
else
{
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">'.$msgText.'</div>');
}
redirect(base_url('index.php/studentDashboardController/loadGeneralProfilePage'));
}
else
{
$this->load->view('login/loginView');
}
}
What I need to do is to first save the user details collected via the form by calling the studentprofileModel's saveUserDetails
method. In this method I need to send the uploaded image's name so that I can store the image path in the db table's image field. And I need to upload the image to the assets folder's subdirectory taro
as well.
I have done the following and the data from the form fields get updated in the DB. But the image file is not uploaded.
Any suggestions in this regard will be highly appreciated