国内流行的内容管理系统(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.

file_manage_control.php 6.1KB

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