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

227 lines
11KB

  1. <?php
  2. /**
  3. * 选择图片
  4. *
  5. * @version $id:select_images.php 2022-07-01 tianya $
  6. * @package DedeBIZ.Dialog
  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_once(dirname(__FILE__)."/config.php");
  12. include(DEDEDATA.'/mark/inc_photowatermark_config.php');
  13. if (empty($activepath)) {
  14. $activepath = '';
  15. }
  16. if (empty($imgstick)) {
  17. $imgstick = '';
  18. }
  19. $noeditor = isset($noeditor) ? $noeditor : '';
  20. $iseditor = isset($iseditor) ? intval($iseditor) : '';
  21. $activepath = str_replace('.', '', $activepath);
  22. $activepath = preg_replace("#\/{1,}#", '/', $activepath);
  23. if (strlen($activepath) < strlen($cfg_image_dir)) {
  24. $activepath = $cfg_image_dir;
  25. }
  26. $inpath = $cfg_basedir.$activepath;
  27. $activeurl = '..'.$activepath;
  28. if (empty($f)) {
  29. $f = 'form1.picname';
  30. }
  31. $f = RemoveXSS($f);
  32. if (empty($v)) {
  33. $v = 'picview';
  34. }
  35. if (empty($comeback)) {
  36. $comeback = '';
  37. }
  38. $addparm = '';
  39. if (!empty($CKEditor)) {
  40. $addparm = '&CKEditor='.$CKEditor;
  41. $f = $CKEditor;
  42. }
  43. if (!empty($CKEditorFuncNum)) {
  44. $addparm .= '&CKEditorFuncNum='.$CKEditorFuncNum;
  45. }
  46. if (!empty($noeditor)) {
  47. $addparm .= '&noeditor=yes';
  48. }
  49. if (!empty($iseditor)) {
  50. $addparm .= '&iseditor='.$iseditor;
  51. }
  52. ?>
  53. <!DOCTYPE html>
  54. <html>
  55. <head>
  56. <meta charset="utf-8">
  57. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  58. <title>选择图片</title>
  59. <link rel="stylesheet" href="../../static/web/font/css/font-awesome.min.css">
  60. <link rel="stylesheet" href="../../static/web/css/bootstrap.min.css">
  61. <link rel="stylesheet" href="../../static/web/css/admin.css">
  62. <script src="../js/float.js"></script>
  63. </head>
  64. <body class="body-bg">
  65. <div class="upload-bg shadow-sm">
  66. <div id="floater" class="napisdiv">
  67. <a href="javascript:nullLink();" onclick="document.getElementById('floater').style.display='none';"><img src="../../static/web/img/icon_img.png" id="picview" title="关闭预览"></a>
  68. </div>
  69. <table align="center" class="table icon">
  70. <tr>
  71. <td colspan="3">
  72. <form name="myform" action="select_images_post.php" method="POST" enctype="multipart/form-data">
  73. <?php $noeditor = !empty($noeditor) ? "<input type='hidden' name='noeditor' value='yes'>" : ''; echo $noeditor;?>
  74. <input type="hidden" name="activepath" value="<?php echo $activepath ?>">
  75. <input type="hidden" name="f" value="<?php echo $f ?>">
  76. <input type="hidden" name="v" value="<?php echo $v ?>">
  77. <input type="hidden" name="iseditor" value="<?php echo $iseditor ?>">
  78. <input type="hidden" name="imgstick" value="<?php echo $imgstick ?>">
  79. <input type="hidden" name="CKEditorFuncNum" value="<?php echo isset($CKEditorFuncNum) ? $CKEditorFuncNum : 1;?>">
  80. <input type="hidden" name="job" value="upload">
  81. <input type="file" name="imgfile" class="w-50">
  82. <label><input type="checkbox" name="needwatermark" value="1" <?php if ($photo_markup == '1') echo "checked";?>> 水印</label>
  83. <label><input type="checkbox" name="resize" value="1"> 缩小</label>
  84. <label>宽:<input type="text" name="iwidth" value="<?php echo $cfg_ddimg_width ?>" class="admin-input-xs"></label>
  85. <label>高:<input type="text" name="iheight" value="<?php echo $cfg_ddimg_height ?>" class="admin-input-xs"></label>
  86. <button type="submit" name="sb1" class="btn btn-success btn-sm">上传</button>
  87. </form>
  88. </td>
  89. </tr>
  90. <tr>
  91. <td colspan="3">点击图片预览,再点击图片关闭预览,点击文件名选择图片</td>
  92. </tr>
  93. <tr>
  94. <td width="40%">选择图片</td>
  95. <td width="26%">文件大小</td>
  96. <td>修改时间</td>
  97. </tr>
  98. <?php
  99. $dh = scandir($inpath);
  100. $ty1 = "";
  101. $ty2 = "";
  102. foreach ($dh as $file) {
  103. //计算文件大小和创建时间
  104. if ($file != "." && $file != ".." && !is_dir("$inpath/$file")) {
  105. $filesize = filesize("$inpath/$file");
  106. $filesize = $filesize / 1024;
  107. if ($filesize != "")
  108. if ($filesize < 0.1) {
  109. @list($ty1, $ty2) = explode("\.", $filesize);
  110. $filesize = $ty1.".".substr($ty2, 0, 2);
  111. } else {
  112. @list($ty1, $ty2) = explode("\.", $filesize);
  113. $filesize = $ty1.".".substr($ty2, 0, 1);
  114. }
  115. $filetime = filemtime("$inpath/$file");
  116. $filetime = MyDate("Y-m-d H:i:s", $filetime);
  117. }
  118. if ($file == ".") continue;
  119. else if ($file == "..") {
  120. if ($activepath == "") continue;
  121. $tmp = preg_replace("#[\/][^\/]*$#i", "", $activepath);
  122. $line = "<tr>
  123. <td colspan='2'><a href='select_images.php?imgstick=$imgstick&v=$v&f=$f&activepath=".urlencode($tmp).$addparm."'><img src='../../static/web/img/icon_dir2.png'>上级目录</a></td>
  124. <td>当前目录:$activepath</td>
  125. </tr>";
  126. echo $line;
  127. } else if (is_dir("$inpath/$file")) {
  128. if (preg_match("#^_(.*)$#i", $file)) continue;
  129. if (preg_match("#^\.(.*)$#i", $file)) continue;
  130. $line = "<tr>
  131. <td colspan='3'><a href='select_images.php?imgstick=$imgstick&v=$v&f=$f&activepath=".urlencode("$activepath/$file").$addparm."'><img src='../../static/web/img/icon_dir.png'>$file</a></td>
  132. </tr>";
  133. echo "$line";
  134. } else if (preg_match("#\.(".$cfg_imgtype.")#i", $file)) {
  135. $reurl = "$activeurl/$file";
  136. $reurl = preg_replace("#^\.\.#", "", $reurl);
  137. $reurl = $reurl;
  138. if ($file == $comeback) $lstyle = "class='text-danger'";
  139. else $lstyle = "";
  140. $line = "<tr>
  141. <td>
  142. <a href=\"javascript:;\" onclick=\"ChangeImage('$reurl');\"><img src='$reurl' title='$file'></a>
  143. <a href=\"javascript:;\" onclick=\"ReturnImg('$reurl');\" $lstyle>$file</a>
  144. </td>
  145. <td>$filesize KB</td>
  146. <td>$filetime</td>
  147. </tr>";
  148. echo "$line";
  149. } else if (preg_match("#\.(jpg)#i", $file)) {
  150. $reurl = "$activeurl/$file";
  151. $reurl = preg_replace("#^\.\.#", "", $reurl);
  152. $reurl = $reurl;
  153. if ($file == $comeback) $lstyle = "class='text-danger'";
  154. else $lstyle = "";
  155. $line = "<tr>
  156. <td>
  157. <a href=\"javascript:;\" onclick=\"ChangeImage('$reurl');\"><img src='$reurl' title='$file'></a>
  158. <a href=\"javascript:;\" onclick=\"ReturnImg('$reurl');\" $lstyle>$file</a>
  159. </td>
  160. <td>$filesize KB</td>
  161. <td>$filetime</td>
  162. </tr>";
  163. echo "$line";
  164. }
  165. }//End Loop
  166. ?>
  167. </tr>
  168. </table>
  169. </div>
  170. <script>
  171. function nullLink() {
  172. return;
  173. }
  174. function ChangeImage(surl) {
  175. document.getElementById('floater').style.display = 'block';
  176. document.getElementById('picview').src = surl;
  177. }
  178. function TNav() {
  179. if (window.navigator.userAgent.indexOf("MSIE") >= 1) return 'IE';
  180. else if (window.navigator.userAgent.indexOf("Firefox") >= 1) return 'FF';
  181. else return "OT";
  182. }
  183. //获取地址参数
  184. function getUrlParam(paramName) {
  185. var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i');
  186. var match = window.location.search.match(reParam);
  187. return (match && match.length > 1) ? match[1] : '';
  188. }
  189. function ReturnImg(reimg) {
  190. var funcNum = getUrlParam('CKEditorFuncNum');
  191. var iseditor = parseInt(getUrlParam('iseditor'));
  192. if (funcNum > 1) {
  193. var fileUrl = reimg;
  194. window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
  195. }
  196. if (iseditor==1) {
  197. let addonHTML = `<img src='${reimg}'>`;
  198. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  199. } else {
  200. if (window.opener.document.<?php echo $f ?> != null) {
  201. window.opener.document.<?php echo $f ?>.value = reimg;
  202. if (window.opener.document.getElementById('div<?php echo $v ?>')) {
  203. if (TNav() == 'IE') {
  204. //window.opener.document.getElementById('div<?php echo $v ?>').filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = reimg;
  205. window.opener.document.getElementById('div<?php echo $v ?>').src = reimg;
  206. window.opener.document.getElementById('div<?php echo $v ?>').style.width = '150px';
  207. window.opener.document.getElementById('div<?php echo $v ?>').style.height = '100px';
  208. } else
  209. window.opener.document.getElementById('div<?php echo $v ?>').style.backgroundImage = "url(" + reimg + ")";
  210. } else if (window.opener.document.getElementById('<?php echo $v ?>')) {
  211. window.opener.document.getElementById('<?php echo $v ?>').src = reimg;
  212. }
  213. //适配新的缩略图
  214. if (window.opener.document.getElementById('litPic')) {
  215. window.opener.document.getElementById('litPic').src = reimg;
  216. }
  217. if (document.all) window.opener = true;
  218. } else if (typeof window.opener.CKEDITOR.instances["<?php echo $f ?>"] !== "undefined") {
  219. let addonHTML = `<img src='${reimg}'>`;
  220. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  221. }
  222. }
  223. window.close();
  224. }
  225. </script>
  226. </body>
  227. </html>