Я пытаюсь сделать функцию загрузки изображения на Codeigniter. но, когда я пытаюсь вставить изображение в базу данных. переменная не может быть обнаружена.
Вот мой контроллер:
public function registrasi() {
//VALIDATION
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email|is_unique[tb_m_user.email]');
$this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[3]|matches[konfirmasi_password]');
$this->form_validation->set_rules('konfirmasi_password', 'Retype Password', 'required|trim|matches[password]');
if($this->form_validation->run() == false) {
$this->session->set_flashdata('fail' , 'Registration Failed! Please Try Again');
$this->load->view('auth/registrasi');
}else{
//INSERT TO DATABASE
$username = $this->input->post('username');
$email = $this->input->post('email');
$password = password_hash($this->input->post('password'), PASSWORD_DEFAULT);
$pict = $_FILES['pict'];
//LIBRARY UPLOAD CONFIG
$config['upload_path'] = '/assets/dist/foto_validasi';
$config['allowed_types'] = 'jpg|png';
$config['file_name'] = date('ymd');
$this->load->library('upload', $config);
if(!$this->upload->do_upload('pict')){
echo "Upload Failed";
}else{
$pict = $this->upload->data('file_name');
}
$data = [
'user_name' => $username,
'email' => $email,
'password' => $password,
'role' => 'pengguna',
'img' => $pict,
'status_aktivasi' => 'tidak aktif',
'created_by' => 'SYSTEM',
];
$this->m_auth->registrasi($data, 'tb_m_user');
$this->session->set_flashdata('success' , 'Registration Successful! Please Login');
Redirect('Auth/login');
}
}
public function login() {
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == false) {
$this->load->view('auth/login');
}else{
$this->postlogin();
}
}
Вот моя форма Просмотр:
<?= form_open_multipart('Auth/registrasi'); ?>
<div class="border-top mt-3">
<div class="ml-2">
<label class="mt-2">Upload Kartu Identitas</label>
</div>
<div class="input-group mb-3">
<input type="file" class="form-control" placeholder="Upload Foto Identitas" name="pict">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-file-image"></span>
</div>
</div>
</div>
<small class="text-danger"><?= form_error('foto') ?></small>
</div>
<?= form_close(); ?>
Вот ошибка: ошибка
Я даже пытался изменить переменная из:
$ pict = $ this-> upload-> data ('имя_файла');
'img' => $ pict,
to:
$ pict2 = $ this-> upload-> data ('имя_файла');
'img' => $ pict2,
но появляется другая ошибка: error2