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

182 lines
5.2KB

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