Ciao a tutti, ho due pagine in cui nella prima c'è un elenco dei
file caricati sul server e database, nella seconda c'è la possibilità di
eliminare i file. Ho usato le sessioni per memorizzare l'id_file per
identificare un determinato file da eliminare ma nella sessione
viene memorizzato sempre l'ultimo id_file.
Questa è la pagina dell'elenco:
Questa è la pagina per eliminare un file:
file caricati sul server e database, nella seconda c'è la possibilità di
eliminare i file. Ho usato le sessioni per memorizzare l'id_file per
identificare un determinato file da eliminare ma nella sessione
viene memorizzato sempre l'ultimo id_file.
Questa è la pagina dell'elenco:
Codice:
<?php
session_start();
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><strong>TITOLO</strong></div></td>
<td><div align="center"><strong>TIPO</strong></div></td>
<td><div align="center"><strong>DIMENSIONE</strong></div></td>
<td><strong>DATA PUBBLICAZIONE </strong></td>
<td><strong>AZIONE</strong></td>
</tr>
<tr>
<?php
include "config_db.php";
$query = "SELECT * FROM upload_file";
$res = mysql_query ($query) or die (mysql_error());
$count_file=0;
while($row= mysql_fetch_array($res)){
$count_file++;
$_SESSION['id_file'] = $row['id_file'];
echo "<td>".$row['titolo']."</td>
<td>".$row['tipo']."</td>
<td>".$row['dimensione']."</td>
<td>".$row['data_pubblicazione']."</td>
<td><a href=\"modifica_file.php\"><img
src=\"images/martinez_01.gif\" alt=\"modifica file\" width=\"16\"
height=\"19\" border=\"0\" /></a>
<a href=\"elimina_file.php?id=".$row['id_file']."\">//qui va bene
<img src=\"images/martinez_03.gif\" alt=\"elimina file\" width=\"14\"
height=\"19\" border=\"0\" /></a></td>
</tr>";
}
?>
</table>
Codice:
<?php
session_start();
?>
VUOI ELIMINARE IL FILE?</strong><strong></strong></p>
<form action="elimina_file.php" method="post"
enctype="multipart/form-data">
<?php
if(isset($_SESSION['id_file'])){
echo "DELETE FROM upload_file WHERE id_file = ".$_SESSION['id_file']; //qui
viene stampato sempre l'ultimo id_file
}
?>
<input type="image" src="images/martinez_10.gif" width="192" height="22"
border="0" /> </form>