1
I am trying to delete simultaneously 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 every row of the table referring to the "logo" fieldand still does not exclude from the folder "upload".
The goal is so that when the user decides to change the image, do not leave the old images overloading the server, since they are no longer being used.
Follow below 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>
Dear Friend: Your script is on the same root, because when you unlink in the folder/file upload/IMAGE FILE NAME. Try to put
error_reporting(E_ALL);
at the beginning of the script to see if an error appears for Voce. Actually this function does not always work, depends on the PHP installation. For it is possible to summarize any error output. No error ? Your PHP is in error mode enabled?– Rogerio Coelho
Good evening, I wonder if my answer helped you? If not, report might have had some doubt in the use of it.
– Guilherme Nascimento
Good evening, I wonder if any of the answers helped you, if not please comment on what you think is missing.
– Guilherme Nascimento