1
Good Afternoon, I’m trying to delete images from the folder and database by php, but unfortunately this error occurs: Warning: unlink(/): Permission denied in C: xampp htdocs Troia FS Galeriaadm.php on line 81. I don’t know how to fix it. how can I fix this error ?
Php code:
<?php
//error_reporting(0);
if(isset($_POST['btnEnviar'])){
$nome = $_FILES['tArq']['name'];
$formato = $_FILES['tArq']['type'];
$n = $_POST['nome'];
$botao = $_POST['botao'];
if (empty($nome)) { echo "<script>alert('Escolha o seu arquivo');</script>"; exit(); }
if (empty($n)) { echo "<script>alert('Digite o nome da equipe.');</script>"; exit(); }
$formatos = array("image/jpg", "image/png", "image/gif", "image/jpeg", "image/bmp", "image/pjpeg");
$testeType = array_search($formato, $formatos);
if(!$testeType){
echo "Formato inválido";
} else {
if(file_exists("fotos/$nome")){
$a = 1;
while(file_exists("fotos/[$a]$nome")){
$a++;
}
$nome = "[".$a."]".$nome;
}
if(move_uploaded_file($_FILES['tArq']['tmp_name'], "fotos/".$nome)){
$insert = "INSERT INTO mantergaleria(`nome`,`foto`) VALUES ('{$n}', '{$nome}')";
mysql_query($insert);
echo "<center> Operação Realizada!!! </center>";
} else {
echo "<center> Operação Realizada!!! </center>";
unlink("fotos/$nome");
}
}
}
if($_POST['botao'] == 'Emitir Relátorio' ){
$sql = "SELECT IdGaleria, nome, foto FROM mantergaleria";
$consulta = mysql_query($sql);
echo '<br><br><table width="400px">';
echo '<tr>';
echo '<td><center><b>Id Galeria</td>';
echo '<td><center><b>Nome</td>';
echo '<td><center><b>Foto</td>';
echo '</tr>';
while($registro = mysql_fetch_assoc($consulta)){
echo '<tr>';
echo '<td><center>'.$registro["IdGaleria"].'</td>';
echo '<td><center>'.$registro["nome"].'</td>';
echo '<td><center>'.$registro["foto"].'</td>';
echo '</tr>';
}
echo '</table>';
}
if($_POST['botao'] == 'Excluir' ){
$result = "DELETE from mantergaleria where IdGaleria = '".$_POST['IdGaleria']."'";
unlink($fotos.'/'.$nome); //LINHA 81
$ver_resultado = @mysql_query($result, $db);
if ($ver_resultado){
echo " <center> Operação Realizada!!! </center>";
}else{
echo "Nao foi possivel excluir"; exit();
echo @mysql_error();
}
}
if($_POST['botao'] == 'Alterar' ){
$result = "UPDATE mantergaleria SET Nome = '".$_POST['Nome']."' WHERE IdGaleria='".$IdGaleria."'";
$ver_resultado = @mysql_query($result, $db);
if ($result){
echo "<center> Operação Realizada!!! </center>";
}else{
echo "Não foi possivel alterar os dados: $Nome, $IdGaleria" ;
echo mysql_error();
}
}
?>
Post the complete code, so it is easier. We need to know about the variable $photos and $name
– Alisson Acioli
I already changed the question
– Ewerton Simonetto
This is a problem with permissions in the folder, where the file is deleted
– rray
The solution is to give the file permission, but I’m even afraid to suggest this, because it’s common for people to open up security when they’re going to do this.
– Maniero