I'm trying to simultaneously delete a certain image that is in the "logo" field of a table that has several other fields, and the folder where it is stored that is called "upload", but I can only delete the entire row of the table referring to the field "logo", and still does not delete it from the "upload" folder.
The purpose is that when the user decides to change the image, do not get the old images overloading the server, since they are no longer being used.
Here is the code I already have:
<?php
include 'conexao.php';
$pasta = 'upload/';
if (isset($_POST['deletar'])){
$check = @$_POST['apagar'];
foreach($check as $logo){
$delcheck = mysql_query("DELETE FROM topo WHERE logo = '$logo'") or die (mysql_error());
unlink($pasta.$delcheck['logo']);
if ($delcheck >= '1'){
echo '<script type="text/javascript">
alert("Deletado com sucesso!");
window.location.href = "listar.php";
</script>';
}else{
echo '<script type="text/javascript">
alert("Erro, tente novamente!");
window.location.href = "listar.php";
</script>';
}}}
?>
<form action="" method="POST" enctype="multipart/form-data"><br />
<?php
include 'conexao.php';
$seleciona = "SELECT * FROM topo";
$queryum = mysql_query($seleciona);
while ($list = mysql_fetch_array($queryum)){
$logo = $list['logo'];
?>
<input type="checkbox" name="apagar[]" value="<?php echo $logo; ?>" readonly><?php echo $logo; ?><br />
<?php
}
?>
<input type="submit" name="deletar" value="Excluir"><br />
</form>