I have this code: And I wanted to delete a file based on the directory address and file it is given, the problem is that it is deleting everything despite the argument (address) that only belongs to a file
DB.php
public function deleteFromFolder($path) {
unlink($path);
}
public function fetchAllRandomImageHighlightsAdmin() {
$sql = ("SELECT 'image_path' FROM 'highlight_image');
$result = $this->_db->prepare($sql);
$result->execute();
return $result->fetchAll(PDO::FETCH_OBJ);
}
public function fetchAllSeveralWorkAdmin() {
$sql = ("SELECT 'image_path' FROM 'several_work_image');
$result = $this->_db->prepare($sql);
$result->execute();
return $result->fetchAll(PDO::FETCH_OBJ);
}
edit.php (delete random image)
if (isset($_POST['idRandom'])) {
$id = $_POST['idRandom'];
foreach ($dataBase->fetchAllRandomImageHighlightsAdmin() as $deleteFile) {
$dataBase->deleteFromFolder($deleteFile->image_path);
}
$dataBase->deleteImageWorkRandom($id);
header('Location: editLisa.php');
}
edit.php (delete several work image)
if (isset($_POST['idSeveral'])) {
$id = $_POST['idSeveral'];
foreach ($dataBase->fetchAllSeveralWorkAdmin() as $deleteFile) {
$dataBase->deleteFromFolder($deleteFile->image_path);
}
$dataBase->deleteImageSeveralWork($id);
header('Location: editLisa.php');
}