Hello community, I need your help. !!
Work on this code:
Code:
public function upload_files($names, $id_usuario){
//Sube archivos
$documentos = new Current_Documentos_Model();
foreach ($names as $archivo => $info) {
if($info['dato'] && $info['valid'] == "is-valid"){ //Valida si existe archvio y es correcto
$file = $this->request->getFile($info['archivo']);
$newName = substr($info['archivo'], 4).'_'.$id_usuario.'.'.$file->getExtension(); //Nombre archivo
$ruta = './imagen/'.$id_usuario; //Ruta archivo
$file->move($ruta,$newName);
if ($file->hasMoved()){
$tbl_document_exists = $documentos->where('alumno_id', $id_usuario)->first();
$documentos->update($tbl_document_exists['ID'], [strtoupper(substr($info['archivo'], 4)) => 1]); //actualiza BD
}
}
}
}
I define the name of the file with the document name followed by the user id.
When uploading a file with the same name I want it to be replaced, but what it does is create a new file with the following user id, as shown in the following image.