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

158 lines
4.8KB

  1. <?php
  2. /**
  3. * 图像查看
  4. *
  5. * @version $Id: pic_view.php 1 15:26 2010年7月20日Z tianya $
  6. * @package DedeCMS.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. {
  23. echo("当前为根目录\n");
  24. }
  25. else
  26. {
  27. $dirs = split("/", $nowPath);
  28. $nowPath = "";
  29. for($i=1; $i<count($dirs)-1; $i++)
  30. {
  31. $nowPath .= "/".$dirs[$i];
  32. }
  33. echo("<a href=\"pic_view.php?activepath=".$nowPath."\">转到上级目录</a>\n");
  34. }
  35. }
  36. function ListPic($truePath, $nowPath)
  37. {
  38. global $listSize;
  39. $col=0;
  40. $rowdd=0;
  41. $rowdd++;
  42. $imgfile="";
  43. $truePath = preg_replace("#\/$#", "", preg_replace("#\\\\{1,}#", "/", trim($truePath)));
  44. $nowPath = preg_replace("#\/$#", "", preg_replace("#\/{1,}#", "/", trim($nowPath)));
  45. $dh = dir($truePath);
  46. echo("<tr align='center'>\n");
  47. while( $filename = $dh->read() )
  48. {
  49. if(!preg_match("#\.$#", $filename))
  50. {
  51. $fullName = $truePath."/".$filename;
  52. $fileUrl = $nowPath."/".$filename;
  53. if(is_dir($fullName))
  54. {
  55. if($col % $listSize==0 && $col != 0)
  56. {
  57. echo("</tr>\n<tr align='center'>\n");
  58. for($i = $rowdd-$listSize; $i < $rowdd; $i++)
  59. {
  60. echo("<td>".$filelist[$i]."</td>\n");
  61. }
  62. echo("</tr>\n<tr align='center'>\n");
  63. }
  64. $line = "
  65. <td>
  66. <table width='106' height='106' border='0' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
  67. <tr><td align='center' bgcolor='#FFFFFF'>
  68. <a href='pic_view.php?activepath=".$fileUrl."'>
  69. <img src='images/pic_dir.gif' width='44' height='42' border='0'>
  70. </a></td></tr></table></td>";
  71. $filelist[$rowdd] = $filename;
  72. $col++;
  73. $rowdd++;
  74. echo $line;
  75. }
  76. else if(IsImg($filename))
  77. {
  78. if($col % $listSize==0 && $col != 0)
  79. {
  80. echo("</tr>\n<tr align='center'>\n");
  81. for($i=$rowdd-$listSize; $i<$rowdd; $i++)
  82. {
  83. echo("<td>".$filelist[$i]."</td>\n");
  84. }
  85. echo("</tr>\n<tr align='center'>\n");
  86. }
  87. $line = "
  88. <td>
  89. <table width='106' height='106' border='0' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
  90. <tr>
  91. <td align='center' bgcolor='#FFFFFF'>
  92. ".GetImgFile($truePath, $nowPath, $filename)."
  93. </td>
  94. </tr></table></td>";
  95. $filelist[$rowdd] = $filename;
  96. $col++;
  97. $rowdd++;
  98. echo $line;
  99. }
  100. }
  101. }
  102. echo("</tr>\n");
  103. if( !empty($filelist) )
  104. {
  105. echo("<tr align='center'>\n");
  106. $t = ($rowdd-1) % $listSize;
  107. if( $t == 0 )
  108. {
  109. $t = $listSize;
  110. }
  111. for($i = $rowdd - $t; $i < $rowdd; $i++)
  112. {
  113. echo("<td>".$filelist[$i]."</td>\n");
  114. }
  115. echo("</tr>\n");
  116. }
  117. }
  118. function GetImgFile($truePath, $nowPath, $fileName)
  119. {
  120. $toW=102;
  121. $toH=102;
  122. $srcFile = $truePath."/".$fileName;
  123. $info = "";
  124. $data = GetImageSize($srcFile, $info);
  125. $srcW=$data[0];
  126. $srcH=$data[1];
  127. if($toW >= $srcW && $toH >= $srcH)
  128. {
  129. $ftoW = $srcW;
  130. $ftoH = $srcH;
  131. }
  132. else
  133. {
  134. $toWH = $toW / $toH;
  135. $srcWH = $srcW / $srcH;
  136. if($toWH <= $srcWH)
  137. {
  138. $ftoW = $toW;
  139. $ftoH = $ftoW * ( $srcH / $srcW);
  140. }
  141. else
  142. {
  143. $ftoH = $toH;
  144. $ftoW = $ftoH * ( $srcW / $srcH );
  145. }
  146. }
  147. return("<a href='".$nowPath."/".$fileName."' target='_blank'><img src='".$nowPath."/".$fileName."' width='".$ftoW."' height='".$ftoH."' border='0'></a>");
  148. }
  149. function IsImg($fileName)
  150. {
  151. if(preg_match("#\.(jpg|gif|png)$#", $fileName)) return 1;
  152. else return 0;
  153. }