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

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