ragazzi ho fatto alcune modifiche nel codice, adesso nel database la foto viene numerata in base all'id progressivo della tabella ma la foto rimane sempre con lo stesso nome, vi posto il nuovo codice:
Codice PHP:
<?php
require 'config.php';
require 'function.php';
// crea cartella
$path_img = "../foto hotel/";
// Creo una array con i formati accettati
$tipi_consentiti = array("image/gif","image/jpeg","image/png");
// verifico che il formato del file sia tra quelli accettati
if (in_array($_FILES['imagefile']['type'], $tipi_consentiti)){
// copio il file nella cartella delle immagini
copy ($_FILES['imagefile']['tmp_name'], $path_img . $_FILES['imagefile']['name']);
// recupero i dati dal form appena caricata
$idhotel = addslashes($_POST['idhotel']);
$descrizione = addslashes($_POST['descrizione']);
$nome = addslashes($_FILES['imagefile']['name']);
$path = $path_img . stripslashes($nome);
$tipo = addslashes($_FILES['imagefile']['type']);
// creo la miniatura
makeThumb($path_img,$path,$nome,$tipo);
// aggiorno il database
$query = "INSERT INTO images (idhotel,descrizione,nome,tipo) VALUES('$idhotel','$descrizione','$nome','$tipo')";
$res = mysql_query($query,$connessione) or die (mysql_error($connessione));
//recupera l'id dall'immagine
$last_id = mysql_insert_id();
// salva immagine con id associato della tabella
$image_id = $last_id;
imagejpeg($tipo, $path_img . '/' . $image_id . '.jpg');
imagedestroy($nome);
$query2 = "UPDATE images SET nome = '" . $image_id. "' WHERE id = '" . $last_id ."' ";
$res = mysql_query($query2,$connessione) or die (mysql_error($connessione));
list($path_img,$path,$nome,$tipo) = getimagesize($path_img . '/' . $image_id .
'.jpg');
if ($_POST['Submit']) {
// make sure the requested image is valid
if (isset($_POST['id']) && ctype_digit($_POST['id']) &&
file_exists($path_img . '/' . $_POST['id'] . '.jpg')) {
$tipo = imagecreatefromjpeg($path_img . '/' . $_POST['id'] . '.jpg');
}
}
echo '<script language=javascript>document.location.href="javascript: history.go(-1)"</script>';
}else{
// stampo un messaggio di errore nel caso in cui il file sia di un formato non consentito
echo "<div align=center>Impossibile eseguire l'upload - DEVI INSERIRE TUTTI I CAMPI.</div>";
}
$url = htmlspecialchars($_SERVER['HTTP_REFERER']);
echo ("
<center>[url='$url']TORNA INDIETRO[/url]</center>");
?>
qulcuno riesce a capire dove sto sbagliando?
Grazie in anticipo