I'm trying to make crud with upload image. When I try to upload it keeps returning failed. I put var_dump it shows false when I put code to show error it returns:
"The upload path does not appear to be valid"
I've been searching for the solution and I found nothing. Can some one help me to find the error:
This is my controller :
public function saveReimburse()
{
validate_submitted_data(array(
'nama' => 'required',
'category_reimburse_id' => 'required',
'amount' => 'required|numeric',
'date_reimburse' => 'required',
// 'photo' => 'required'
));
// data
$data = [
'nama' => $this->input->post('nama'),
'category_reimburse_id' => $this->input->post('category_reimburse_id'),
'amount' => $this->input->post('amount'),
'date_reimburse' => $this->input->post('date_reimburse'),
'photo' => $_FILES['photo'],
// 'status'=> $this->input->post("PENDING"),
// 'nama' => $this->input->post('nama'),
];
// condition
$date = date('Y-m-d');
$date = strtotime($date);
$date = strtotime('-7 day', $date);
if ($data['date_reimburse'] < date('Y-m-d', $date)) {
echo json_encode(array('succes' => FALSE, 'message' => 'Max Reimburse was 1 week ago'));
} else {
// var_dump($data);
// exit;
if ($data['photo'] = "") {
} else {
$config = [
'upload_path' => is_dir('assets/reimburse/') . 'assets/reimburse/',
'allowed_types' => 'jpg|png|gif',
'overwrite' => TRUE
];
$this->load->library('upload', $config);
$upload = $this->upload->do_upload('photo');
var_dump($config);
print_r($this->upload->display_errors());exit;
var_dump($upload);exit;
if (!$upload) {
json_encode(array('success' => FALSE, 'message' => 'Failed Upload'));
redirect('Reimburse/index', 'refresh');
} else {
$this->upload->data('file_name');
$save = $this->reimburseModel->saveReimburse('reimburse', $data);
var_dump($data);exit;
if (!$save) {
echo json_encode(array('success' => FALSE, 'message' => 'Failed to reccord'));
} else {
redirect('Reimburse/index', 'refresh');
echo json_encode(array('success' => TRUE, 'message' => 'Reimburse Success'));
}
}
}
}
}
You have to use base_path for physical path in codeigniter.
$base_path = $this->config->item('base_path');
Then Use $base_path as your project folder root directory and you can access any folder from your project folder to upload images.
Like. $base_path.'/'.'upload/';