У меня есть вид, где пользователь может редактировать свои данные.Загрузка изображения в CodeIgniter с использованием PHP
Посмотреть
<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>
Контроллер
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');
}
}
Что мне нужно сделать, это первый сохранить пользовательские данные, собранные через форму с помощью вызова метода studentprofileModel's saveUserDetails
. В этом методе мне нужно отправить имя загруженного изображения, чтобы сохранить путь изображения в поле изображения таблицы db. И мне нужно загрузить изображение в папку с ресурсами subdirectory taro
.
Я сделал следующее, и данные из полей формы обновляются в БД. Но файл изображения не загружается.
Любые предложения в этой связи будут высоко оценены
любая ошибка, которую вы получаете? проверьте выгрузку этой функции '$ this-> upload-> display_errors());' и добавьте 'enctype =" multipart/form-data "' в свой тег формы –
В вашем представлении есть '