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

116 lines
4.8KB

  1. <?php
  2. /**
  3. * 模块上传
  4. *
  5. * @version $Id: module_upload.php 1 14:43 2010年7月20日Z tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__) . "/config.php");
  12. CheckPurview('sys_module');
  13. require_once(dirname(__FILE__) . "/../include/dedemodule.class.php");
  14. require_once(dirname(__FILE__) . "/../include/oxwindow.class.php");
  15. if (empty($action)) $action = '';
  16. $mdir = DEDEDATA . '/module';
  17. if ($action == 'upload') {
  18. if (!is_uploaded_file($upfile)) {
  19. ShowMsg("貌似你什么都没有上传哦!", "javascript:;");
  20. exit();
  21. } else {
  22. include_once(dirname(__FILE__) . "/../include/zip.class.php");
  23. $tmpfilename = $mdir . '/' . ExecTime() . mt_rand(10000, 50000) . '.tmp';
  24. move_uploaded_file($upfile, $tmpfilename) or die("把上传的文件移动到{$tmpfilename}时失败,请检查{$mdir}目录是否有写入权限!");
  25. //ZIP格式的文件
  26. if ($filetype == 1) {
  27. $z = new zip();
  28. $files = $z->get_List($tmpfilename);
  29. $dedefileindex = -1;
  30. //为了节省资源,系统仅以.xml作为扩展名识别ZIP包里了dede模块格式文件
  31. if (is_array($files)) {
  32. for ($i = 0; $i < count($files); $i++) {
  33. if (preg_match("#\.xml#i", $files[$i]['filename'])) {
  34. $dedefile = $files[$i]['filename'];
  35. $dedefileindex = $i;
  36. break;
  37. }
  38. }
  39. }
  40. if ($dedefileindex == -1) {
  41. unlink($tmpfilename);
  42. ShowMsg("对不起,你上传的压缩包中不存在dede模块文件!<br /><br /><a href='javascript:history.go(-1);'>&gt;&gt;返回重新上传&gt;&gt;</a>", "javascript:;");
  43. exit();
  44. }
  45. $ziptmp = $mdir . '/ziptmp';
  46. $z->Extract($tmpfilename, $ziptmp, $dedefileindex);
  47. unlink($tmpfilename);
  48. $tmpfilename = $mdir . "/ziptmp/" . $dedefile;
  49. }
  50. $dm = new DedeModule($mdir);
  51. $infos = $dm->GetModuleInfo($tmpfilename, 'file');
  52. if (empty($infos['hash'])) {
  53. unlink($tmpfilename);
  54. $dm->Clear();
  55. ShowMsg("对不起,你上传的文件可能不是织梦模块的标准格式文件!<br /><br /><a href='javascript:history.go(-1);'>&gt;&gt;返回重新上传&gt;&gt;</a>", "javascript:;");
  56. exit();
  57. }
  58. if (preg_match("#[^0-9a-zA-Z]#", $infos['hash'])) {
  59. exit("hash check failed!");
  60. }
  61. $okfile = $mdir . '/' . $infos['hash'] . '.xml';
  62. if ($dm->HasModule($infos['hash']) && empty($delhas)) {
  63. unlink($tmpfilename);
  64. $dm->Clear();
  65. ShowMsg("对不起,你上传的模块已经存在,<br />如果要覆盖请先删除原来版本或选择强制删除的选项!<br /><br /><a href='javascript:history.go(-1);'>&gt;&gt;返回重新上传&gt;&gt;</a>", "javascript:;");
  66. exit();
  67. }
  68. @unlink($okfile);
  69. copy($tmpfilename, $okfile);
  70. @unlink($tmpfilename);
  71. $dm->Clear();
  72. ShowMsg("成功上传一个新的模块!", "module_main.php?action=view&hash={$infos['hash']}");
  73. exit();
  74. }
  75. } else {
  76. $win = new OxWindow();
  77. $win->Init("module_upload.php", "js/blank.js", "POST' enctype='multipart/form-data");
  78. $win->mainTitle = "模块管理";
  79. $wecome_info = "<a href='module_main.php'>模块管理</a> &gt;&gt; 上传模块";
  80. $win->AddTitle('请选择要上传的文件:');
  81. $win->AddHidden("action", 'upload');
  82. $msg = "
  83. <table width='600' border='0' cellspacing='0' cellpadding='0'>
  84. <tr>
  85. <td height='30'>文件格式:</td>
  86. <td>
  87. <label><input name='filetype' type='radio' value='0' checked='checked' />
  88. 正常的模块包</label>
  89. <label><input type='radio' name='filetype' value='1' />
  90. 经过 zip 压缩的模块包</label> </td>
  91. </tr>
  92. <tr>
  93. <td height='30'>已有模块:</td>
  94. <td>
  95. <label><input name='delhas' type='checkbox' id='delhas' value='1' /> 强制删除同名模块(这可能导致已经安装的模块无法卸载)</label>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td width='96' height='60'>请选择文件:</td>
  100. <td width='504'>
  101. <input name='upfile' type='file' id='upfile' style='width:380px' /> </td>
  102. </tr>
  103. </table>
  104. ";
  105. $win->AddMsgItem("<div style='padding-left:20px;line-height:150%;'>$msg</div>");
  106. $winform = $win->GetWindow('ok', '');
  107. $win->Display();
  108. exit();
  109. }
  110. //ClearAllLink();