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

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