I'm trying to get the name of an image in the controller of a Codeigniter project, however, I can not get it.
This is my method:
public function add() {
$path = 'img/noticias/';
$config = array(
'upload_path' => "./img/noticias/",
'allowed_types' => "jpg|png|jpeg",
'overwrite' => TRUE,
'max_size' => "2048000",
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('addImage')) {
$mensaje = array('error' => $this->upload->display_errors());
die($mensaje['error']);
}
$file_info = $this->upload->data('addImage');
$file_name = $file_info['file_type'];
$datos = array(
'autor' => $this->input->post('addAutor'),
'nombre' => $this->input->post('addNombre'),
'ruta' => $path.$file_name,
'link' => $this->input->post('addLink')
);
echo "Nombre: ".$file_name;
die();
$resultado = $this->Articulos_Model->agregaArticulo($datos);
if ($resultado) {
redirect('index.php/Articulos', 'refresh');
}
}
At the time of printing it on the screen, it does not show me the name
This is my front, I'm using a modal:
<!-- Add Modal-->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="editaArticulo" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<?php echo form_open_multipart('index.php/Articulos/add'); ?>
<div class="modal-header">
<h5 class="modal-title text-center" id="editaArticulo">Agregar Artículo</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<div class="form-label-group">
<input name="addAutor" type="text" id="addAutor" class="form-control" placeholder="Autor" required="required" autofocus="autofocus">
<label for="addAutor">Autor</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input name="addNombre" type="text" id="addNombre" class="form-control" placeholder="Nombre Artículo" required="required" autofocus="autofocus">
<label for="addNombre">Nombre Artículo</label>
</div>
</div>
<div class="form-group">
<label for="addFile">Eligir imagen</label>
<input name="addImage" type="file" class="form-control-file" id="addFile" accept="image/png,image/jpg,image/jpeg">
</div>
<div class="form-group">
<div class="form-label-group">
<input name="addLink" type="text" id="addLink" class="form-control" placeholder="Link del Artículo" required="required" autofocus="autofocus">
<label for="addLink">Link del Artículo</label>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<button class="btn btn-success" type="submit">Añadir</button>
</div>
<?php echo form_close(); ?>
</div>
</div>