largeimage è il file temporaneo che arriva dal form
ecco il codice intero
Codice PHP:
if (isset($_POST["del_id"])) {
$id_categoria=$_POST["del_id"];
$del_id="vero";
}else{$del_id="falso";}
if (isset($_POST["upimg"])) {
$up="vero";
$id_categoria=$_POST["upimg"];
$LARGEFILE=$_FILES["largeimage"]["name"]; // CON FILES
$val_sottocategoria = $_POST["sottocategoria"];
}else{$up="falso";}
if (isset($_POST["categoria"])){
$id_categoria = $_POST["categoria"];
}
?>
</head>
<body>
<?php
//eliminazione dell'indirizzo delle foto dal db
if ($del_id=="vero"){
$sql_foto="SELECT galleria.FOTO, galleria.ID_CONTATORE FROM galleria WHERE galleria.ID_CATEGORIA = " .$id_categoria;
$result_foto = mysql_query("$sql_foto")or die (mysql_error());
$righe_foto = mysql_num_rows($result_foto);
if ($righe_foto!=0) {
$counter=0;
for ($counter=0;$counter<$righe_foto;$counter++){
mysql_data_seek($result_foto,$counter);
$riga=mysql_fetch_assoc($result_foto);
$id=$riga["ID_CONTATORE"];
if (isset($_POST[$id])){
$sqldel="DELETE FROM galleria WHERE galleria.ID_CONTATORE='$id'";
mysql_query("$sqldel") or die (mysql_error());
}
}
}
}
//-----------------------------------------------
?>
<table width="900" border="0" cellpadding="0" cellspacing="0" align="center">
<tr align="center" valign="bottom">
<td height="40" colspan="5" class="Title">[b]Inserimento di una Nuova Foto - (Foto Galleria)[/b]</td>
</tr>
<tr>
<td height="23" colspan="5" valign="top"><hr color="#FF9900" size="5"></td>
</tr>
<tr>
<td width="166" height="53"></td>
<td width="22"></td>
<td width="622" align="center" valign="top">
[b]ATTENZIONE![/b]</p>
[i]Attenersi alle indicazioni riportate nel modulo. L'inserimento di
una foto troppo grande potrebbe compromettere l'operazione di upload del
file ed il layout della pagina.[/i]</p></td>
<td width="25"></td>
<td width="189"></td>
</tr>
<tr>
<td height="115"></td>
<td colspan="3" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<form action="?page=gallery" enctype="multipart/form-data" method="post" name="UploadFile">
<tr>
<td width="209" height="40" align="right" valign="middle">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1024000">
</td>
</tr>
<tr>
<td height="40" align="right" valign="middle">
File Immagine [i](jpg, gif)[/i]</p></td>
<td colspan="2" align="left" valign="middle"> <input size="35" type="file" name="largeimage"></td>
</tr>
<tr>
<td height="20" align="right" valign="middle">
Scegli una sottocategoria</p></td>
<td colspan="2" align="left" valign="middle">
<?php
//fai una query
$query = mysql_query("SELECT * FROM sub_categorie_gallery");
//apro il tag select per il menu a tendina
echo"<select name=\"sottocategoria\">";
//metto i risultati della query in un array e poi faccio un ciclo
while($row = mysql_fetch_array($query))
{
//stampo option con value uguale alla regione e il testo è la regione
echo "<option value=\"".$row['nome']."\">".$row['nome']."</option>";
}
//finito il ciclo chiudo il tag select
echo"</select>";
?>
</td>
</tr>
<tr>
<td height="20" align="right" valign="middle">Descrizione breve</td>
<td colspan="2" align="left" valign="middle"><input size="45" type="text" name="descrizione"></td>
</tr>
<tr>
<td height="35" align="right" valign="bottom"> <p class="Indented">
<input type="hidden" name="upimg" value="<? echo $id_categoria;?>">
<input type="reset" value="Ripristina">
</p></td>
<td width="160" align="left" valign="bottom"><p class="Indented">
<input type="submit" value="Esegui Upload">
</p></td>
<td width="219" align="center" valign="bottom"><font size="-2">[i]* MAX 150 FOTO[/i]</font></td>
</tr>
</form>
</table></td>
<td></td>
</tr>
<tr>
<td height="15"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr align="center" valign="middle">
<td height="55" colspan="5">
<?php
$sql_foto="SELECT galleria.FOTO FROM galleria WHERE galleria.ID_CATEGORIA = " .$id_categoria;
$result_foto = mysql_query("$sql_foto")or die (mysql_error());
$righe_foto = mysql_num_rows($result_foto);
if ($sql_foto<150){
$foto="ok";
}else{
$foto="ko";
}
if (($foto=="ok") && ($up=="vero")) {
//upload dei file e salvataggio nel db
$save="ko";
$a=$_SERVER['DOCUMENT_ROOT'];
$path = "/home/httpd/vhosts/sito.it/httpdocs/public/foto_salento";
if (($largeimage != 'none')) {
print("Percorso locale: $largeimage -- ");
print("Nome del file: $largeimage -- ");
print("Dimensione del file: $largeimage_size -- ");
print("Tipo di file: $largeimage_type --
");
print("<HR/>
");
$Filedest="Salento_" .$id_categoria ."_" .$largeimage_name;
if (move_uploaded_file( $largeimage , "/home/httpd/vhosts/sito.it/httpdocs/public/foto_salento/" .$Filedest )){
print "$largeimage copiato con successo in $path/$Filedest";
$POS = strrpos($LARGEFILE,"/");
$FILE1 = "Salento_" .$id_categoria ."_";
$FILE2 = substr($LARGEFILE,$POS);
$save="ok";
}else{print "Errore.. upload non riuscito
"; print $path; $save="ko";}
unlink($largeimage);
}else{print "Errore.. nessun file.";$save="ko";}
// fine upload primo file
if ($save="ok") {
$stringsql = "INSERT INTO galleria (ID_CATEGORIA, FOTO, CATEGORIA, SOTTOCATEGORIA, DESCRIZIONE) VALUES ('$id_categoria','$FILE1$FILE2', '$id_categoria', '$val_sottocategoria', '$descrizione')";
$result_2 = mysql_query($stringsql) or die (mysql_error());
}
}else{
if ($foto=="ko")
{echo $foto ."-" .$up ."SI E' RAGGIUNTO IL NUMERO MASSIMO DI FOTO CONSENTITE";}
}
?> </td>
</tr>
<tr>
<td height="25"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="130" colspan="5" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<form action="?page=gallery" enctype="multipart/form-data" method="post" name="ELIMINA">
<?php
// apro la tabella che ci servirà per l'impaginazione
echo "<table>";
// recupero i dati dal DB
$query = "SELECT * FROM galleria WHERE galleria.ID_CATEGORIA = " .$id_categoria;
$res = mysql_query($query) or die (mysql_error());
// numero delle immagini presenti nel DB
$n_img = mysql_num_rows($res);
// verifico che il DB ospiti almeno un'immagine
if($n_img >= 1 ){
// stabilisco il numero di righe e colonne della nostra tabella per l'impagninazione
$colonne = 5;
$righe=0;
// ciclo tutti i record recuperati attraverso la nostra query
while ($f=@mysql_fetch_array($res)){
$righe++;
$idfoto = $f['ID_CONTATORE'];
$titolo = stripslashes($f['FOTO']);
$id_categoria = stripslashes($f['CATEGORIA']);
$descrizione = stripslashes($f['DESCRIZIONE']);
// stampo la cella contenente l'immagine
echo "<td align=\"center\">\n";
//echo $titolo . "
";
echo "<input type=checkbox name='$idfoto' value='$idfoto'>
";
echo "<a href=\"/gestionale/?page=visualizza_gallery&action=edit&id=". $idfoto . "\" target=\"blank\">";
//echo "<a href=\"/public/foto_salento/Salento_". $id_categoria ."_". $titolo . "\" target=\"blank\">";
//echo "<img src=\"/public/foto_salento/Salento_". $id_categoria ."_". $titolo . "\" border=\"0\" height=\"87\" width=\"116\" alt=". $descrizione ."></a>
";
echo "
" . $titolo;
echo "</td>\n";
// quando il numero di righe equivale al valore impostato nella variabile $righe
// procedo a chiudere la linea e ad azzerare il valore di $righe
if ($righe == $colonne){
echo "</tr><tr>\n";
$righe = 0;
}
}
}else{
// stampo un messaggio se il DB è vuoto
echo "Nessuna immagine inserita.";
}
echo "<tr><td colspan=5 height=25 align=center><input type=hidden name=del_id value='$id_categoria'><input type=reset value='Ripristina'><input type=submit value='Elimina Selezionati'>";
@mysql_close($cn);
echo "</table>";
?>
</form>
</body>
</html>