I'm trying for some time to delete images from a folder through an unlink inside a loop
, in the case while
, however I'm encountering the error:
PHP Warning: unlink (admin / imgsupload / 32acafa5b1bac0d2af522f76627e3212.jpg) [function.unlink]: No such file or directory in /home/storage/1/05/41/lcjprojetos/public_html/admin/excluirprojeto.php on line 19, referer: link
From what I understand the error is telling me that the directory or file does not exist. But I have already checked and both the directory and the image exist, I tried to give the complete path and without results as well. Here is the code:
<?php
include 'seguranca.php';
include 'conexao.php';
$url = $_SERVER['REQUEST_URI'];
$parteurl = explode('/', $url);
$id = $parteurl[3];
$teste=mysqli_real_escape_string($conexao,$id);
$sql2 = "SELECT * FROM 'galeriafotos' WHERE 'codigo'=".$teste."";
$resultado2 = mysqli_query($conexao, $sql2) or die (mysql_error());
$itens=mysqli_fetch_assoc($resultado2) or die (mysql_error());
unlink("admin/imgsupload/".$itens['imagem']);
$link=$itens['link'];
$sql3 = "SELECT * FROM 'fotos' WHERE 'link'='$link'";
$resultado3 = mysqli_query($conexao, $sql3) or die (mysql_error());
$itens2=mysqli_fetch_assoc($resultado3) or die (mysql_error());
while($itens2){
unlink("admin/imgsupload/".$itens2['imagem']);
}
$sql = "DELETE FROM 'fotos'
WHERE 'link' ='$link'";
$resultado = mysqli_query($conexao, $sql);
$sql4 = "DELETE FROM 'galeriafotos'
WHERE 'link' ='$link'";
$resultado4 = mysqli_query($conexao, $sql4);
if($resultado4){
echo " < <script>window.location.replace('http://www.lcjprojetos.com.br/admin/projetos');</script>";
}
?>
Structure, this code is in the admin folder, where the imgsupload folder is also located: