Browse Source

Delete image when deleting article

keplyx 4 years ago
parent
commit
517d4cdf4a
1 changed files with 13 additions and 0 deletions
  1. 13
    0
      classes/postHandler.php

+ 13
- 0
classes/postHandler.php View File

@@ -81,6 +81,17 @@ class PostHandler
81 81
             return json_encode($this->filesData)."id: ".$this->data;
82 82
     }
83 83
 
84
+    private function remove_image() {
85
+        $uploadPath = $this->uploadBaseDir.$this->data["id"].".jpg";
86
+        if (file_exists($uploadPath) && unlink($uploadPath)) {
87
+            $this->responseArray["message"] = "Success: Deleted image";
88
+        } else if (!file_exists($uploadPath)) {
89
+            $this->responseArray["message"] = "Success: No image to delete";
90
+        } else {
91
+            $this->responseArray["message"] = "Success: Could not delete image";
92
+        }
93
+    }
94
+
84 95
     function create()
85 96
     {
86 97
         $result = -1;
@@ -114,6 +125,8 @@ class PostHandler
114 125
         $result = -1;
115 126
         if ($this->type == "article") {
116 127
             $result = $this->dao->remove_article($this->data);
128
+            if ($result != 0)
129
+                $this->remove_image();
117 130
         } else if ($this->type == "category") {
118 131
             $result = $this->dao->remove_category($this->data);
119 132
         } else

Loading…
Cancel
Save