Uploadfiy.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\service\common;
  10. use app\common\service\upload\Uploadfiy as UploadfiyService;
  11. use app\common\models\Attachments as AttachmentsModel;
  12. use think\facade\Config;
  13. class Uploadfiy extends UploadfiyService {
  14. /**
  15. * 删除附件
  16. * @param $path
  17. * @return false
  18. */
  19. public static function delete($path){
  20. if(empty($path) || !AttachmentsModel::where(["path"=>$path])->delete()){
  21. return false;
  22. }
  23. $path = str_replace("\\",'/',trim($path,"/"));
  24. $config = Config::get("base.thumb_image_list");
  25. $arr = explode("/",$path);
  26. $file = end($arr);
  27. file_exists($path) && unlink($path);
  28. // 如果是图片检查是否有缩略图,存在缩略图删除。
  29. $suffix = explode(".",$file);
  30. $suffix = end($suffix);
  31. if(in_array($suffix,["jpg","png","gif","jpeg","bmp"])){
  32. foreach($config as $key=>$val){
  33. $thumb = str_replace($file, $key . '_' . $file, $path);
  34. file_exists($thumb) && unlink($thumb);
  35. }
  36. }
  37. return true;
  38. }
  39. }