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

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