Delete image when deleting article

This commit is contained in:
keplyx 2020-02-14 12:11:42 +01:00
parent 3b50449d56
commit 517d4cdf4a

View file

@ -81,6 +81,17 @@ class PostHandler
return json_encode($this->filesData)."id: ".$this->data; return json_encode($this->filesData)."id: ".$this->data;
} }
private function remove_image() {
$uploadPath = $this->uploadBaseDir.$this->data["id"].".jpg";
if (file_exists($uploadPath) && unlink($uploadPath)) {
$this->responseArray["message"] = "Success: Deleted image";
} else if (!file_exists($uploadPath)) {
$this->responseArray["message"] = "Success: No image to delete";
} else {
$this->responseArray["message"] = "Success: Could not delete image";
}
}
function create() function create()
{ {
$result = -1; $result = -1;
@ -114,6 +125,8 @@ class PostHandler
$result = -1; $result = -1;
if ($this->type == "article") { if ($this->type == "article") {
$result = $this->dao->remove_article($this->data); $result = $this->dao->remove_article($this->data);
if ($result != 0)
$this->remove_image();
} else if ($this->type == "category") { } else if ($this->type == "category") {
$result = $this->dao->remove_category($this->data); $result = $this->dao->remove_category($this->data);
} else } else