Hola buenos días.
Me interesaría introducir un número aleatorio para evitar duplicidad en archivos subidos al servidor.
¿Dónde tengo que colocarlo? ""substr(md5(uniqid(rand())),0,6)""
Intento con este, pero puede ser otro.
Muchas gracias.
Código PHP:
Ver original<?php require_once('../../Connections/contactos.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ?
intval($theValue) : "NULL"; break;
case "double":
$theValue = ($theValue != "") ?
doubleval($theValue) : "NULL"; break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$query_Recordset1 = "SELECT * FROM contactos";
?>
.......
<?
$nombre=$_POST[nombre];
$apellido=$_POST[apellido];
$ciudad=$_POST[ciudad];
$provincia=$_POST[provincia];
$web=$_POST[web];
$tituloanuncio=$_POST[tituloanuncio];
$precio=$_POST[precio];
$foto1 = $_FILES['foto1']['name'];
// "directorio" es el directorio donde vas a subir la imagen.
mysql_query("insert into contactos(foto1 , nombre , apellido , ciudad , provincia , web , tituloanuncio , precio) values('/imagenes/$foto1','$nombre','$apellido','$ciudad','$provincia','$web','$tituloanuncio','$precio')",$db) or
die("La clave introducida, ya existe. Elige otra");
//ahora subamos la imagen, "directorio" es el directorio donde la vas a subir.
$copy = copy($_FILES['foto1']['tmp_name'], "../../imagenes/" . $_FILES['foto1']['name']); ?> </h1>
<!-- end #mainContent --></div>
<!-- Este elemento de eliminación siempre debe ir inmediatamente después del div #mainContent para forzar al div #container a que contenga todos los elementos flotantes hijos --><br class="clearfloat" />
<div id="footer">
<p>Pie</p>
<!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
<?php
?>