*/ namespace app\enterprise\model; use app\BaseModel; class File extends BaseModel { protected $pk="file_id"; // 同步彻底删除文件 public static function syncDelFile($file_id) { if ($file_id) { $file = new self(); $item = $file->where('file_id', $file_id)->find(); $Emoji = Emoji::where(['file_id'=>$file_id,'delete_time'=>0])->find(); if ($Emoji) { return false; } $PostsFile = PostsFile::where(['file_id'=>$file_id,'delete_time'=>0])->find(); if ($PostsFile) { return false; } $Message = Message::where(['file_id' => $file_id])->find(); if ($Message) { return false; } if ($item) { // 删除文件 $filename_dir = root_path(); $file_path = $filename_dir . 'public/' . ltrim($item->src,'/'); if (file_exists($file_path)) { unlink($file_path); } // 删除图片 $compress_img = $item->compress_img; if ($compress_img) { $img_path = $filename_dir . 'public/' . ltrim($compress_img,'/'); if (file_exists($img_path)) { unlink($img_path); } } // 删除图片数据 $file->where('file_id', $file_id)->delete(); return true; } } return false; } }