瀏覽代碼

Update User\deleteAvatar()

Visman 4 年之前
父節點
當前提交
baaee97733
共有 1 個文件被更改,包括 8 次插入5 次删除
  1. 8 5
      app/Models/User/Model.php

+ 8 - 5
app/Models/User/Model.php

@@ -178,13 +178,16 @@ class Model extends DataModel
     public function deleteAvatar(): void
     {
         $file = $this->getAttr('avatar');
-        $path = $this->c->DIR_PUBLIC . "{$this->c->config->o_avatars_dir}/{$file}";
 
-        if (\is_file($path)) {
-            @\unlink($path);
-        }
+        if (! empty($file)) {
+            $path = $this->c->DIR_PUBLIC . "{$this->c->config->o_avatars_dir}/{$file}";
 
-        $this->avatar = '';
+            if (\is_file($path)) {
+                @\unlink($path);
+            }
+
+            $this->avatar = '';
+        }
     }
 
     /**