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

222 lines
10KB

  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/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="/static/web/js/jquery.min.js"></script>
  63. </head>
  64. <body>
  65. <div class="upload-box shadow-sm">
  66. <table class="table icon">
  67. <tr>
  68. <td colspan="3">
  69. <form name="myform" action="select_images_post.php" method="POST" enctype="multipart/form-data">
  70. <?php $noeditor = !empty($noeditor) ? "<input type='hidden' name='noeditor' value='yes'>" : ''; echo $noeditor;?>
  71. <input type="hidden" name="activepath" value="<?php echo $activepath ?>">
  72. <input type="hidden" name="f" value="<?php echo $f ?>">
  73. <input type="hidden" name="v" value="<?php echo $v ?>">
  74. <input type="hidden" name="iseditor" value="<?php echo $iseditor ?>">
  75. <input type="hidden" name="imgstick" value="<?php echo $imgstick ?>">
  76. <input type="hidden" name="CKEditorFuncNum" value="<?php echo isset($CKEditorFuncNum) ? $CKEditorFuncNum : 1;?>">
  77. <input type="hidden" name="job" value="upload">
  78. <input type="file" name="imgfile" class="w-50">
  79. <label><input type="checkbox" name="needwatermark" value="1" <?php if ($photo_markup == '1') echo 'checked';?>> 水印</label>
  80. <label><input type="checkbox" name="resize" value="1"> 缩小</label>
  81. <label>宽:<input type="text" name="iwidth" value="<?php echo $cfg_ddimg_width ?>" class="admin-input-xs"></label>
  82. <label>高:<input type="text" name="iheight" value="<?php echo $cfg_ddimg_height ?>" class="admin-input-xs"></label>
  83. <button type="submit" name="sb1" class="btn btn-success btn-sm">上传</button>
  84. </form>
  85. </td>
  86. </tr>
  87. <tr>
  88. <td colspan="3">点击图片预览,再点击图片关闭预览,点击文件名选择图片</td>
  89. </tr>
  90. <tr>
  91. <td width="40%">选择图片</td>
  92. <td width="26%">文件大小</td>
  93. <td>修改时间</td>
  94. </tr>
  95. <?php
  96. $dh = scandir($inpath);
  97. $ty1 = '';
  98. $ty2 = '';
  99. foreach ($dh as $file) {
  100. //计算文件大小和创建时间
  101. if ($file != "." && $file != ".." && !is_dir("$inpath/$file")) {
  102. $filesize = filesize("$inpath/$file");
  103. $filesize = $filesize / 1024;
  104. if ($filesize != "")
  105. if ($filesize < 0.1) {
  106. @list($ty1, $ty2) = explode("\.", $filesize);
  107. $filesize = $ty1.".".substr($ty2, 0, 2);
  108. } else {
  109. @list($ty1, $ty2) = explode("\.", $filesize);
  110. $filesize = $ty1.".".substr($ty2, 0, 1);
  111. }
  112. $filetime = filemtime("$inpath/$file");
  113. $filetime = MyDate("Y-m-d H:i:s", $filetime);
  114. }
  115. if ($file == ".") continue;
  116. else if ($file == "..") {
  117. if ($activepath == "") continue;
  118. $tmp = preg_replace("#[\/][^\/]*$#i", "", $activepath);
  119. $line = "<tr>
  120. <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>
  121. <td>当前目录:$activepath</td>
  122. </tr>";
  123. echo $line;
  124. } else if (is_dir("$inpath/$file")) {
  125. if (preg_match("#^_(.*)$#i", $file)) continue;
  126. if (preg_match("#^\.(.*)$#i", $file)) continue;
  127. $line = "<tr>
  128. <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>
  129. </tr>";
  130. echo "$line";
  131. } else if (preg_match("#\.(".$cfg_imgtype.")#i", $file)) {
  132. $reurl = "$activeurl/$file";
  133. $reurl = preg_replace("#^\.\.#", "", $reurl);
  134. $reurl = $reurl;
  135. if ($file == $comeback) $lstyle = "text-danger";
  136. else $lstyle = '';
  137. $line = "<tr>
  138. <td>
  139. <a href='$reurl' onclick=\"ReturnImg('$reurl');\" class=\"tipsimg $lstyle\"><img src='$reurl' title='$file'> $file</a>
  140. </td>
  141. <td>$filesize KB</td>
  142. <td>$filetime</td>
  143. </tr>";
  144. echo "$line";
  145. } else if (preg_match("#\.(jpg)#i", $file)) {
  146. $reurl = "$activeurl/$file";
  147. $reurl = preg_replace("#^\.\.#", "", $reurl);
  148. $reurl = $reurl;
  149. if ($file == $comeback) $lstyle = "text-danger";
  150. else $lstyle = '';
  151. $line = "<tr>
  152. <td><a href='$reurl' onclick=\"ReturnImg('$reurl');\" class=\"tipsimg $lstyle\"><img src='$reurl' title='$file'> $file</a></td>
  153. <td>$filesize KB</td>
  154. <td>$filetime</td>
  155. </tr>";
  156. echo "$line";
  157. }
  158. }//End Loop
  159. ?>
  160. </tr>
  161. </table>
  162. </div>
  163. <script>
  164. function nullLink() {
  165. return;
  166. }
  167. //获取地址参数
  168. function getUrlParam(paramName) {
  169. var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i');
  170. var match = window.location.search.match(reParam);
  171. return (match && match.length > 1) ? match[1] : '';
  172. }
  173. function ReturnImg(reimg) {
  174. var funcNum = getUrlParam('CKEditorFuncNum');
  175. var iseditor = parseInt(getUrlParam('iseditor'));
  176. if (funcNum > 1) {
  177. var fileUrl = reimg;
  178. window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
  179. }
  180. if (iseditor==1) {
  181. let addonHTML = `<img src='${reimg}'>`;
  182. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  183. } else {
  184. if (window.opener.document.<?php echo $f ?> != null) {
  185. window.opener.document.<?php echo $f ?>.value = reimg;
  186. if (window.opener.document.getElementById('div<?php echo $v ?>')) {
  187. window.opener.document.getElementById('<?php echo $v ?>').src = reimg;
  188. }
  189. //适配新的缩略图
  190. if (window.opener.document.getElementById('litPic')) {
  191. window.opener.document.getElementById('litPic').src = reimg;
  192. }
  193. if (document.all) window.opener = true;
  194. } else if (typeof window.opener.CKEDITOR.instances["<?php echo $f ?>"] !== "undefined") {
  195. let addonHTML = `<img src='${reimg}'>`;
  196. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  197. }
  198. }
  199. window.close();
  200. }
  201. $(function() {
  202. var x = 10;
  203. var y = 10;
  204. $(".tipsimg").mouseover(function(e) {
  205. var toolimg = "<div id='toolimg'><img src='" + this.href + "'></div>";
  206. $("body").append(toolimg);
  207. $("#toolimg").css({
  208. "top": (e.pageY + y) + "px",
  209. "left": (e.pageX + x) + "px"
  210. }).show("fast");
  211. }).mouseout(function() {
  212. $("#toolimg").remove();
  213. }).mousemove(function(e) {
  214. $("#toolimg").css({
  215. "top": (e.pageY + y) + "px",
  216. "left": (e.pageX + x) + "px"
  217. });
  218. });
  219. });
  220. </script>
  221. </body>
  222. </html>