Piccolo problema che non capisco!!!
ho creato delle pagine tra cui una che mi elimina delle immagini nelle cartelle e il percorso dal database solo che nel momento in cui carico la pagina per vedere i dati mi tira fuori gli indici non aggiornati in ordine tipo passa dal 25 al 27 se ho eliminato ad esempio la 26 ma la pagina che visualizza i dati mi tira fuori una riga che non esiste che corrisponde all'indice 26 (eliminato) come correggo questo problema? posto il codice sia dell'insert che della tabella
upload.php
Codice PHP:
include("config.php");
include('connessione.php');
//if the for has submittedd
if (isset($_POST['upForm'])){
$file_type = $_FILES['imgfile']['type'];
$file_name = $_FILES['imgfile']['name'];
$file_size = $_FILES['imgfile']['size'];
$file_tmp = $_FILES['imgfile']['tmp_name'];
$descrizione = $_POST['descrizione'];
//check if you have selected a file.
if(!is_uploaded_file($file_tmp)){
header("Location: upload_immagini.php"); /* Redirect browser */
exit(); //exit the script and don't do anything else.
}
//check file extension
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
echo "Wrong file extension.
--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
exit();
}
//get the file extension.
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
$rand_name = md5(time());
$rand_name= rand(0,999999999);
//get the new width variable.
$ThumbWidth = $img_thumb_width;
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img = imagecreatefromgif($file_tmp);
}
//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$imgratio;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$resized_img = imagecreatetruecolor($newwidth,$newheight);
}else{
die("Error: Please make sure you have GD library ver 2+");
}
imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//save image
ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
//print message
//echo "
Image Thumb: <a href=\"$path_thumbs/$rand_name.$file_ext\">$path_thumbs/$rand_name.$file_ext</a>";
}
//upload the big image
move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
//echo "
Image Big: <a href=\"$path_big/$rand_name.$file_ext\">$path_big/$rand_name.$file_ext</a>";
//echo "
--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
//echo "$rand_name.$file_ext";
$query = "INSERT INTO `fotoband` (`id`,`big`,`thumbs`, `descrizione`, `rand_name`) VALUES ('', '$path_big/$rand_name.$file_ext', '$path_thumbs/$rand_name.$file_ext', '$descrizione', '$rand_name')";
/* //test for insert db ok
echo "$path_big/$rand_name.$file_ext";
echo "
";
echo "$path_thumbs/$rand_name.$file_ext";
echo "
";
echo "$descrizione";
echo "
";
*/
$result = mysql_query($query) or die("Query failed: ".mysql_error());
if($result) {
echo "<div class='err'>
L'immagine è stata inserita correttamente
</div>";
echo "<meta http-equiv=refresh content=2;url=upload_immagini.php>";
} else {
echo "<div class='err'>
Errore inserimento immagine.</div>";
}
}else{ //if the form hasn't been submitted.
//print the form
echo "
<div id='margini02'>
<form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"$_SERVER[PHP_SELF]\">
<table width='450' cellspacing='0' cellpadding='0' border='0' align='center' bgcolor='#ffffff'>
<tr>
<td colspan='3' height='40'></td>
</tr>
<tr>
<td colspan='3'><div class='h3'>:: Inserisci le immagini singolarmente tramite Upload:</div></td>
</tr>
</table>
<div id='bordo_contorni2'>
<table width='450' cellspacing='0' cellpadding='0' border='0' align='center'>
<tr>
<td colspan='3' height='30'></td>
</tr>
<tr>
<td class='h5'>Immagine:</td>
<td width='30'></td>
<td><input type='file' name='imgfile' class='inputbox'></td>
</tr>
<tr>
<td colspan='3' height='10'></td>
</tr>
<tr>
<td class='h5'>Descrizione:</td>
<td width='30'></td>
<td><input class='inputbox' type=\"text\" name=\"descrizione\" maxlength=\"150\" /></td>
</tr>
<tr>
<td colspan='3' height='10'></td>
</tr>
<tr>
<td></td>
<td width='30'></td>
<td><input type=\"Submit\" name=\"upForm\" value=\"Upload\" class='submit'></td>
</tr>
<tr>
<td colspan='3' height='30'></td>
</tr>
</table>
</div>
</form>
</div>";
}
?>
tabella
Codice PHP:
CREATE TABLE `fotoband` (
`id` int(11) NOT NULL auto_increment,
`big` varchar(100) default NULL,
`thumbs` varchar(100) NOT NULL,
`rand_name` varchar(20) NOT NULL,
`descrizione` mediumtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=96 DEFAULT CHARSET=latin1 AUTO_INCREMENT=96 ;