The logic by which you can only store a name of up to 50 characters would belong to the model part and although you should pass the "prepared" data to the "registro()"
method, it would be "appropriate" to prepare the length of that name in the own method before mounting the INSERT .
Actually you should use a private method of the class to do that, or you'd rather create one in a helper class (which you could name StringTools , for example) in order to prepare the name if it is too long (and even if it is not).
A method that adapts the name of the file can allow you; preserve letters instead of spaces, replace spaces with scripts, substitute years for enes or remove accents (less future problems), etc. It is also advisable to use mb_substr () instead of substr () , which will not cut your 50 characters if you find accents, eñes, etc ...
You can see the documentation: link
And your method would look like this:
public function registro( $nombre_pdf, $autor, $fecha, $archivo, $carrera ) {
$nombre_pdf = StringTools::prepareFileName( $nombre_pdf );
$sql = "INSERT INTO tesis (
nombre_pdf,
autor,
fecha,
archivo,
carrera
) VALUES (
'$nombre_pdf',
'$autor',
'$fecha',
'$archivo',
'$carrera'
)";
$consulta = $this->conecta()->query( $sql );
echo '<script language="javascript">
alert("Los datos se registraron con exito");
window.location.href="index.php";
</script>';
}
And StringTools :: prepareFileName () would have as its purpose to change something like this:
"Éste puede ser un nombre demasiado largo para almacenar"
for this other:
"EstePuedeSerUnNombreDemasiadoLargoParaAlmacenar"
Writing it in another class will allow you to use it from other points of your application and easily take it to other projects.
One thing I do not like, although it is not part of the question is that you have code of sight (the alert) in the method that is storing information in the database, I recommend studying the MVC pattern strong>. In this respect, your method could return a boolean and generate a 'feedback' where appropriate.
Greetings.