国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.9KB

  1. <?php
  2. /**
  3. * 文件管理器操作
  4. *
  5. * @version $id:file_manage_control.php 8:48 2010年7月13日 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  9. * @link https://www.dedebiz.com
  10. */
  11. require(dirname(__FILE__)."/config.php");
  12. CheckPurview('plus_文件管理器');
  13. require(DEDEINC."/libraries/oxwindow.class.php");
  14. require_once(DEDEADMIN.'/file_class.php');
  15. $activepath = str_replace("..", "", $activepath);
  16. $activepath = preg_replace("#^\/{1,}#", "/", $activepath);
  17. if ($activepath == "/") $activepath = '';
  18. if ($activepath == "") $inpath = $cfg_basedir;
  19. else $inpath = $cfg_basedir.$activepath;
  20. $files = json_decode(file_get_contents(DEDEDATA.'/admin/files.txt'));
  21. $currentFolder = basename(__DIR__);
  22. $realFiles = array();
  23. foreach ($files as $ff) {
  24. $rfi = preg_replace("#^admin/#",$currentFolder.'/',$ff->filename);
  25. $realFiles[] = $rfi;
  26. }
  27. function realdir($path) {
  28. return dirname(realpath($path));
  29. }
  30. //文件管理器交互与逻辑控制文件
  31. $fmm = new FileManagement();
  32. $fmm->Init();
  33. if ($fmdo == "rename") {
  34. $f = str_replace("..", "", $oldfilename);
  35. $f = $cfg_basedir.$activepath."/$oldfilename";
  36. if (!file_exists(dirname(__FILE__).'/../license.txt')) {
  37. ShowMsg("许可协议不存在,无法重名文件", "javascript:;");
  38. exit();
  39. }
  40. $f = str_replace(realdir(dirname(__FILE__).'/../license.txt').'/', "", $f);
  41. if (in_array($f,$realFiles)) {
  42. ShowMsg("系统文件禁止重名", "javascript:;");
  43. exit();
  44. }
  45. $oldfilename = str_replace("..","",$oldfilename);
  46. $newfilename = str_replace("..","",$newfilename);
  47. $fmm->RenameFile($oldfilename, $newfilename);
  48. }
  49. //新建目录
  50. else if ($fmdo == "newdir") {
  51. CheckCSRF();
  52. $fmm->NewDir($newpath);
  53. }
  54. //移动文件
  55. else if ($fmdo == "move") {
  56. $f = str_replace("..", "", $filename);
  57. $f = $cfg_basedir.$activepath."/$filename";
  58. if (!file_exists(dirname(__FILE__).'/../license.txt')) {
  59. ShowMsg("许可协议不存在,无法移动文件", "javascript:;");
  60. exit();
  61. }
  62. $f = str_replace(realdir(dirname(__FILE__).'/../license.txt').'/', "", $f);
  63. if (in_array($f,$realFiles)) {
  64. ShowMsg("系统文件禁止移动", "javascript:;");
  65. exit();
  66. }
  67. $fmm->MoveFile($filename, $newpath);
  68. }
  69. //删除文件
  70. else if ($fmdo == "del") {
  71. $f = str_replace("..", "", $filename);
  72. $f = $cfg_basedir.$activepath."/$filename";
  73. if (!file_exists(dirname(__FILE__).'/../license.txt')) {
  74. ShowMsg("许可协议不存在,无法删除", "javascript:;");
  75. exit();
  76. }
  77. $f = str_replace(realdir(dirname(__FILE__).'/../license.txt').'/', "", $f);
  78. if (in_array($f,$realFiles)) {
  79. ShowMsg("系统文件禁止删除", "javascript:;");
  80. exit();
  81. }
  82. $fmm->DeleteFile($filename);
  83. }
  84. //文件修改
  85. else if ($fmdo == "edit") {
  86. CheckCSRF();
  87. $filename = str_replace("..", "", $filename);
  88. if (preg_match('#\.(php|pl|cgi|asp|aspx|jsp|php5|php4|php3|shtm|shtml)$#i', trim($filename))) {
  89. ShowMsg("文件扩展名已被系统禁止", "javascript:;");
  90. exit();
  91. }
  92. $file = "$cfg_basedir$activepath/$filename";
  93. $str = stripslashes($str);
  94. $fp = fopen($file, "w");
  95. fputs($fp, $str);
  96. fclose($fp);
  97. if (empty($backurl)) {
  98. ShowMsg("成功保存一个文件", "file_manage_main.php?activepath=$activepath");
  99. } else {
  100. ShowMsg("成功保存一个文件", $backurl);
  101. }
  102. exit();
  103. }
  104. //文件上传
  105. else if ($fmdo == "upload") {
  106. $j = 0;
  107. for ($i = 1; $i <= 50; $i++) {
  108. $upfile = "upfile".$i;
  109. $upfile_name = "upfile".$i."_name";
  110. if (!isset(${$upfile}) || !isset(${$upfile_name})) {
  111. continue;
  112. }
  113. $upfile = ${$upfile};
  114. $upfile_name = ${$upfile_name};
  115. if (preg_match('#\.(php|pl|cgi|asp|aspx|jsp|php5|php4|php3|shtm|shtml)$#i', trim($upfile_name))) {
  116. ShowMsg("文件扩展名已被系统禁止", "javascript:;");
  117. exit();
  118. }
  119. if (is_uploaded_file($upfile)) {
  120. //检查文件类型
  121. $mime = get_mime_type($upfile);
  122. if (preg_match("#^unknow#", $mime)) {
  123. ShowMsg("系统不支持fileinfo组件,建议php.ini中开启", -1);
  124. exit;
  125. }
  126. if (!preg_match("#^(image|video|audio|application)#i", $mime)) {
  127. ShowMsg("仅支持媒体文件及应用程序上传", -1);
  128. exit;
  129. }
  130. if (!file_exists($cfg_basedir.$activepath."/".$upfile_name)) {
  131. move_uploaded_file($upfile, $cfg_basedir.$activepath."/".$upfile_name);
  132. }
  133. @unlink($upfile);
  134. $j++;
  135. }
  136. }
  137. ShowMsg("成功上传".$j."个文件到".$activepath."", "file_manage_main.php?activepath=$activepath");
  138. exit();
  139. }
  140. //空间检查
  141. else if ($fmdo == "space") {
  142. if ($activepath == "") {
  143. $ecpath = "所有目录";
  144. } else {
  145. $ecpath = $activepath;
  146. }
  147. $wintitle = "指定空间检查大小";
  148. $wecome_info = "文件管理器 - <a href='file_manage_main.php?activepath=$activepath'>$ecpath</a>空间检查大小";
  149. $activepath = $cfg_basedir.$activepath;
  150. $space = new SpaceUse;
  151. $space->checksize($activepath);
  152. $total = $space->totalsize;
  153. $totalkb = $space->setkb($total);
  154. $totalmb = $space->setmb($total);
  155. $win = new OxWindow();
  156. $win->Init("", "/static/web/js/admin.blank.js", "POST");
  157. $win->AddMsgItem("<tr>
  158. <td>
  159. <span>$totalkb</span>KB<br>
  160. <span>$totalmb</span>M<br>
  161. <span>$total</span>字节
  162. </td>
  163. </tr>
  164. <tr>
  165. <td align='center'><button type='button' class='btn btn-success btn-sm' onclick=\"location='file_manage_main.php';\">文件管理器</button></td>
  166. </tr>");
  167. $winform = $win->GetWindow("");
  168. $win->Display();
  169. }
  170. ?>