how to rename an image when saving in a database

1

I want to save an image in the database but at the time of saving, if 2 have the same name one replaces the other, as I check that if there is one with that name, I will change the name to the other one.

at the moment like this I have the code:

$Id_u = $_SESSION["Id"];
$clv_e = isset($_POST['clv_e']) ? $_POST['clv_e'] : null;
$seccion = isset($_POST['seccion']) ? $_POST['seccion'] : null;
$foto =  isset($_FILES['foto']['name']) ? $_FILES['foto']['name'] : null;
$ruta = isset($_FILES['foto']['tmp_name']) ? $_FILES['foto']['tmp_name'] : 
null;
$destino="Fotos/".$foto;
$_SESSION['foto']= $foto;


If($clv_e!=""){ 
copy($ruta,$destino);   
$qry=mysql_query("insert into 
registros(clave_electoral,seccion,imagen,estado,Id_usuario) values 
('".$clv_e."','".$seccion."','".$destino."','Activo','".$Id_u."');"
);

    
asked by Juan Lozano 11.04.2018 в 19:18
source

1 answer

1

Make the temporary file that you create have a function that creates a new name in case it already exists and thus does not duplicate the name. I would change the Destiny Names of the Copy () or Bien Haria A Function that in the Final Destination of the Files create New Names for the Files so that they do not repeat themselves.

    
answered by 11.10.2018 в 15:55