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

138 lines
4.7KB

  1. <?php
  2. /**
  3. * 图像查看
  4. *
  5. * @version $Id: pic_view.php 1 15:26 2010年7月20日Z tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__) . "/config.php");
  12. CheckPurview('pic_view');
  13. if (empty($activepath)) $activepath = $cfg_medias_dir;
  14. $activepath = preg_replace("#\/{1,}#", "/", $activepath);
  15. $activepath = RemoveXSS($activepath);
  16. $truePath = $cfg_basedir . $activepath;
  17. $listSize = 5;
  18. include DedeInclude('templets/pic_view.htm');
  19. function GetPrePath($nowPath)
  20. {
  21. if ($nowPath == "" || $nowPath == "/") {
  22. echo ("当前为根目录\n");
  23. } else {
  24. $dirs = split("/", $nowPath);
  25. $nowPath = "";
  26. for ($i = 1; $i < count($dirs) - 1; $i++) {
  27. $nowPath .= "/" . $dirs[$i];
  28. }
  29. echo ("<a href=\"pic_view.php?activepath=" . $nowPath . "\">转到上级目录</a>\n");
  30. }
  31. }
  32. function ListPic($truePath, $nowPath)
  33. {
  34. global $listSize;
  35. $col = 0;
  36. $rowdd = 0;
  37. $rowdd++;
  38. $imgfile = "";
  39. $truePath = preg_replace("#\/$#", "", preg_replace("#\\\\{1,}#", "/", trim($truePath)));
  40. $nowPath = preg_replace("#\/$#", "", preg_replace("#\/{1,}#", "/", trim($nowPath)));
  41. $dh = dir($truePath);
  42. echo ("<tr align='center'>\n");
  43. while ($filename = $dh->read()) {
  44. if (!preg_match("#\.$#", $filename)) {
  45. $fullName = $truePath . "/" . $filename;
  46. $fileUrl = $nowPath . "/" . $filename;
  47. if (is_dir($fullName)) {
  48. if ($col % $listSize == 0 && $col != 0) {
  49. echo ("</tr>\n<tr align='center'>\n");
  50. for ($i = $rowdd - $listSize; $i < $rowdd; $i++) {
  51. echo ("<td>" . $filelist[$i] . "</td>\n");
  52. }
  53. echo ("</tr>\n<tr align='center'>\n");
  54. }
  55. $line = "
  56. <td>
  57. <table width='106' height='106' border='0' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
  58. <tr><td align='center' bgcolor='#FFFFFF'>
  59. <a href='pic_view.php?activepath=" . $fileUrl . "'>
  60. <img src='images/pic_dir.gif' width='44' height='42' border='0'>
  61. </a></td></tr></table></td>";
  62. $filelist[$rowdd] = $filename;
  63. $col++;
  64. $rowdd++;
  65. echo $line;
  66. } else if (IsImg($filename)) {
  67. if ($col % $listSize == 0 && $col != 0) {
  68. echo ("</tr>\n<tr align='center'>\n");
  69. for ($i = $rowdd - $listSize; $i < $rowdd; $i++) {
  70. echo ("<td>" . $filelist[$i] . "</td>\n");
  71. }
  72. echo ("</tr>\n<tr align='center'>\n");
  73. }
  74. $line = "
  75. <td>
  76. <table width='106' height='106' border='0' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
  77. <tr>
  78. <td align='center' bgcolor='#FFFFFF'>
  79. " . GetImgFile($truePath, $nowPath, $filename) . "
  80. </td>
  81. </tr></table></td>";
  82. $filelist[$rowdd] = $filename;
  83. $col++;
  84. $rowdd++;
  85. echo $line;
  86. }
  87. }
  88. }
  89. echo ("</tr>\n");
  90. if (!empty($filelist)) {
  91. echo ("<tr align='center'>\n");
  92. $t = ($rowdd - 1) % $listSize;
  93. if ($t == 0) {
  94. $t = $listSize;
  95. }
  96. for ($i = $rowdd - $t; $i < $rowdd; $i++) {
  97. echo ("<td>" . $filelist[$i] . "</td>\n");
  98. }
  99. echo ("</tr>\n");
  100. }
  101. }
  102. function GetImgFile($truePath, $nowPath, $fileName)
  103. {
  104. $toW = 102;
  105. $toH = 102;
  106. $srcFile = $truePath . "/" . $fileName;
  107. $info = "";
  108. $data = GetImageSize($srcFile, $info);
  109. $srcW = $data[0];
  110. $srcH = $data[1];
  111. if ($toW >= $srcW && $toH >= $srcH) {
  112. $ftoW = $srcW;
  113. $ftoH = $srcH;
  114. } else {
  115. $toWH = $toW / $toH;
  116. $srcWH = $srcW / $srcH;
  117. if ($toWH <= $srcWH) {
  118. $ftoW = $toW;
  119. $ftoH = $ftoW * ($srcH / $srcW);
  120. } else {
  121. $ftoH = $toH;
  122. $ftoW = $ftoH * ($srcW / $srcH);
  123. }
  124. }
  125. return ("<a href='" . $nowPath . "/" . $fileName . "' target='_blank'><img src='" . $nowPath . "/" . $fileName . "' width='" . $ftoW . "' height='" . $ftoH . "' border='0'></a>");
  126. }
  127. function IsImg($fileName)
  128. {
  129. if (preg_match("#\.(jpg|gif|png)$#", $fileName)) return 1;
  130. else return 0;
  131. }