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