TrojanController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\backend\modules\setting\controllers;
  3. use app\common\components\BaseController;
  4. use Illuminate\Filesystem\Filesystem;
  5. class TrojanController extends BaseController
  6. {
  7. public function check()
  8. {
  9. if(request()->ajax()){
  10. $del_files = [];
  11. if (config('app.framework') != 'platform') {
  12. $path = base_path() . '/../../attachment/image';
  13. } else {
  14. $path = base_path('static/upload');
  15. }
  16. if (request()->trojan == 'check') {
  17. $filesystem = app(Filesystem::class);
  18. $files = $filesystem->allFiles($path);
  19. foreach ($files as $item) {
  20. if ($item->getExtension() == 'php') {
  21. $del_files[] = $item->getPathname();
  22. }
  23. }
  24. }
  25. return $this->successJson('请求接口成功',[
  26. 'files' => $del_files,
  27. 'del_file' => implode('|', $del_files)
  28. ]);
  29. }
  30. return view('setting.trojan.check');
  31. }
  32. public function del()
  33. {
  34. $files = request()->files;
  35. if (!empty($files)) {
  36. $filesystem = app(Filesystem::class);
  37. foreach ($files as $file) {
  38. if (!$filesystem->delete($file)) {
  39. return $this->errorJson('删除失败');
  40. }
  41. }
  42. return $this->successJson('删除成功');
  43. }
  44. return $this->errorJson('删除失败');
  45. }
  46. }