Delete image when deleting article
This commit is contained in:
parent
3b50449d56
commit
517d4cdf4a
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue