心理咨询网
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ImageExtController.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\model\content\CompanyModel;
  4. use app\admin\model\content\ContentModel;
  5. use app\admin\model\content\ContentSortModel;
  6. use app\admin\model\content\LinkModel;
  7. use app\admin\model\content\SiteModel;
  8. use app\admin\model\content\SlideModel;
  9. use app\admin\model\content\LabelModel;
  10. use app\home\model\MemberModel;
  11. use core\basic\Controller;
  12. class ImageExtController extends Controller
  13. {
  14. private $companyModel;
  15. private $contentSortModel;
  16. private $contentModel;
  17. private $linkModel;
  18. private $memberModel;
  19. private $siteModel;
  20. private $slideModel;
  21. private $LabelModel;
  22. public function __construct()
  23. {
  24. $this->companyModel = new CompanyModel();
  25. $this->contentSortModel = new ContentSortModel();
  26. $this->contentModel = new ContentModel();
  27. $this->linkModel = new LinkModel();
  28. $this->memberModel = new MemberModel();
  29. $this->siteModel = new SiteModel();
  30. $this->slideModel = new SlideModel();
  31. $this->LabelModel = new LabelModel();
  32. }
  33. public function index()
  34. {
  35. $this->display('system/extimage.html');
  36. }
  37. public function checkDataFile()
  38. {
  39. $count = 30;
  40. $page = get('page') ? get('page') : 1;
  41. $start = ($page - 1) * $count;
  42. $dataArr = [];
  43. $company = $this->companyModel->getImage();
  44. $contentSort = $this->contentSortModel->getImage();
  45. $content = $this->contentModel->getImage();
  46. $link = $this->linkModel->getImage();
  47. $member = $this->memberModel->getImage();
  48. $site = $this->siteModel->getImage();
  49. $slide = $this->slideModel->getImage();
  50. $label = $this->LabelModel->getImage();
  51. $resArr = array_merge_recursive($company, $contentSort, $content, $link, $member, $site, $slide, $label);
  52. array_walk_recursive($resArr, function ($key1) use (&$dataArr) {
  53. if (!empty($key1)) {
  54. $dataArr[] = DOC_PATH . SITE_DIR .$key1;
  55. }
  56. return $dataArr;
  57. });
  58. $dataArr = array_unique($dataArr);
  59. //获取上传的文件
  60. $Filepath = DOC_PATH . STATIC_DIR . '/upload';
  61. $fileList = get_dir($Filepath);
  62. $fileArr = [];
  63. array_walk_recursive($fileList, function ($key) use (&$fileArr) {
  64. $fileArr[] = $key;
  65. return $fileArr;
  66. });
  67. //对比文件
  68. $difference = array_diff($fileArr, $dataArr);
  69. $pageList = array_slice($difference, $start, $count);
  70. $http = is_https() ? 'https://' : 'http://';
  71. foreach ($pageList as &$value) {
  72. $value = [
  73. 'real_path' => $value,
  74. 'static_path' => $http . $_SERVER['SERVER_NAME'] . str_replace(DOC_PATH, '', $value),
  75. 'update_time' => date('Y-m-d H:i:s', filemtime($value))
  76. ];
  77. }
  78. $jsonData = ['code' => 0,'msg'=> '', 'count' => count($difference),'data' => $pageList];
  79. return json_encode($jsonData);
  80. }
  81. public function do_ext()
  82. {
  83. $type = post('type');
  84. $list = post('list');
  85. $movePath = DOC_PATH . STATIC_DIR . '/backup/ImageExt';
  86. check_dir($movePath, true);
  87. switch ($type){
  88. case 0:
  89. //清理所选文件
  90. foreach ($list as $value){
  91. $fileName = substr(strrchr($value['real_path'], "/"), 1);
  92. $filePath = strstr($value['real_path'],'/static');
  93. $fileDir = str_replace($fileName,'',$filePath);
  94. check_dir($movePath . $fileDir, true);
  95. rename($value['real_path'], $movePath . $filePath);
  96. }
  97. break;
  98. case 1:
  99. //清理所有冗余文件
  100. //获取上传的文件
  101. $Filepath = DOC_PATH . STATIC_DIR . '/upload';
  102. $fileList = get_dir($Filepath);
  103. $fileArr = [];
  104. array_walk_recursive($fileList, function ($key) use (&$fileArr) {
  105. $fileArr[] = $key;
  106. return $fileArr;
  107. });
  108. //查询数据
  109. $dataArr = [];
  110. $company = $this->companyModel->getImage();
  111. $contentSort = $this->contentSortModel->getImage();
  112. $content = $this->contentModel->getImage();
  113. $link = $this->linkModel->getImage();
  114. $member = $this->memberModel->getImage();
  115. $site = $this->siteModel->getImage();
  116. $slide = $this->slideModel->getImage();
  117. $Label = $this->LabelModel->getImage();
  118. $resArr = array_merge_recursive($company, $contentSort, $content, $link, $member, $site, $slide, $Label);
  119. array_walk_recursive($resArr, function ($key1) use (&$dataArr) {
  120. if (!empty($key1)) {
  121. $dataArr[] = DOC_PATH . SITE_DIR .$key1;
  122. }
  123. return $dataArr;
  124. });
  125. $dataArr = array_unique($dataArr);
  126. //对比文件并执行文件迁移
  127. $difference = array_diff($fileArr, $dataArr);
  128. $movePath = DOC_PATH . STATIC_DIR . '/backup/ImageExt/';
  129. check_dir($movePath, true);
  130. foreach ($difference as $path) {
  131. $fileName = substr(strrchr($path, "/"), 1);
  132. $filePath = strstr($path,'/static');
  133. $fileDir = str_replace($fileName,'',$filePath);
  134. check_dir($movePath . $fileDir, true);
  135. rename($path, $movePath . $filePath);
  136. }
  137. break;
  138. }
  139. json(1,'');
  140. }
  141. }