Delete image when deleting article

这个提交包含在:
keplyx 2020-02-14 12:11:42 +01:00
父节点 3b50449d56
当前提交 517d4cdf4a

查看文件

@ -81,6 +81,17 @@ class PostHandler
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()
{
$result = -1;
@ -114,6 +125,8 @@ class PostHandler
$result = -1;
if ($this->type == "article") {
$result = $this->dao->remove_article($this->data);
if ($result != 0)
$this->remove_image();
} else if ($this->type == "category") {
$result = $this->dao->remove_category($this->data);
} else