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

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