*/ 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(); 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); } } // 删除图片数据 $item->delete(); } // 同步删除表情包 $Emoji = Emoji::where('file_id', $file_id)->find(); if ($Emoji) { $Emoji->delete(); } } } }