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

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