1
I’m having trouble deleting a file from the file, when I pass a "GET", it deletes all files from the file I have to pass some variable to identify the file name?
<?php
if(isset($_SERVER['REQUEST_METHOD']) AND $_SERVER['REQUEST_METHOD']=='GET'){
$pasta = 'uploads/photos/';
if(is_dir($pasta)){
$diretorio = dir($pasta);
while($arquivo = $diretorio->read()){
$arquivo = ''.$resphotos['photo'].'';
if(($arquivo!='.')&&($arquivo!='..')){
$id = $arquivo = ''.$resphotos['id'].'';
$del = DB::getConn()->prepare('DELETE FROM `photos` WHERE `id`=? LIMIT 1');
return $del->execute(array($id));
unlink($pasta.$arquivo);
echo'<span> o arquivo foi apagado</span>';
}
}
}
$diretorio->close();
}else{
echo'a pasta nao existe';
}
?>
It’s kind of weird this code, there’s a
return $del->execute()
then aunlink()
?– rray
where the
$resphotos['id']
?– RFL
resphotos is from the album class @Rafael Acioly is the function that selects in the table
– David
@rray this Return is to delete the BD file I am beginner in php, mainly in PHPOO
– David
Return will cancel all lines of code below it, ie it leaves the function
– rray
@rray I removed the Return , but when I delete the photo does not erase the right photo, delete the first uploaded photo from the album, and so on
– David