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
$categoria=$_FILES["categoria"]["name"];
print_r($_FILES);
$sottocategoria=$_FILES["sottocategoria"]["name"];
$descrizione=$_FILES["descrizione"]["name"];
}else{$up="falso";}
if (isset($_GET["id"])){
$id_categoria = $_GET["id"];
}
$db_host = "xxxxxxxxxxxxxxxx";
$db_user = "xxxxxxxxxx";
$db_password = "xxxxxxxxxx";
$db_name = "xxxxxxxxxxxxx";
$connection = mysql_pconnect("$db_host","$db_user","$db_password") or die ("Impossibile connettersi al database!");
mysql_select_db("$db_name", $connection) or die("Impossibile accedere al database!");
?>
</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", $connection)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",$connection) or die (mysql_error());
}
}
}
}
//-----------------------------------------------
?>
...omissis html...
<td width="22"></td>
<td align="center" valign="top">
ATTENZIONE!</p>
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.</p></td>
...omissis html...
<form action="gallery.php" 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 (jpg, gif)</p></td>
<td colspan="2" align="left" valign="middle"> <input size="35" type="file" name="largeimage"></td>
</tr>
<tr>
<td height="40" align="right" valign="middle">
Categoria</p></td>
<td colspan="2" align="left" valign="middle">
<?php
//fai una query
$query = mysql_query("SELECT * FROM categorie_gallery ORDER BY nome ASC");
//apro il tag select per il menu a tendina
echo"<select name=\"categoria\">";
//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['id']."\">".$row['nome']."</option>";
}
//finito il ciclo chiudo il tag select
echo"</select>";
?>
</select>
Sottocategoria
<?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>";
?>
</select>
</td>
</tr>
<tr>
<td height="40" align="right" valign="middle">
Descrizione breve</p></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">* MAX 150 FOTO</font></td>
</tr>
</form>
...omissis html...
<?php
$sql_foto="SELECT galleria.FOTO FROM galleria WHERE galleria.ID_CATEGORIA = " .$id_categoria;
$result_foto = mysql_query("$sql_foto", $connection)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 = "/////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 (copy( $largeimage , $path . "/" .$Filedest )){
print "$largeimage copiato con successo in $path/$Filedest";
$POS = strrpos($LARGEFILE,"/");
$FILE = substr($LARGEFILE,$POS);
$save="ok";
}else{print "Errore.. upload non riuscito
";$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','$FILE', '$categoria', '$sottocategoria', '$descrizione')";
$result_2 = mysql_query($stringsql, $connection) 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="gallery.php" enctype="multipart/form-data" method="post" name="ELIMINA">
<?php
$sql_foto="SELECT galleria.FOTO, galleria.ID_CONTATORE FROM galleria WHERE galleria.ID_CATEGORIA = " .$id_categoria;
$result_foto = mysql_query("$sql_foto", $connection)or die (mysql_error());
$righe_foto = mysql_num_rows($result_foto);
$counter = 0;
if ($righe_foto != 0) {
echo "<tr>";
for ($counter=0;$counter<$righe_foto;$counter++){
mysql_data_seek($result_foto,$counter);
$riga_foto = mysql_fetch_assoc($result_foto);
if ($counter<150){
$idfoto=$riga_foto["ID_CONTATORE"];
echo "<td width=100 height=100 align=center valign=middle><input type=checkbox name='$idfoto' value='$idfoto'>
<img src=/////foto_salento/Salento_" .$id_categoria ."_" .$riga_foto["FOTO"] ." width=100 alt='foto n° " .($counter+1) ."'></td>";
}
}
echo "</tr>";
echo "<tr><td colspan=5 height=25 align=right><input type=hidden name=del_id value='$id_categoria'><input type=reset value='Ripristina'></td><td colspan=5 height=25 align=left><input type=submit value='Elimina Selezionati'></td></tr>";
}
?>
...omissis html...
</tr>
</form>
...omissis html...
</table>
</body>
</html>