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