1. <?php
2.
3. class FileFun
4. {
5.
6. function display_filelist($directory)
7. {
8. $handle=opendir($directory);
9. $dirlist=array();
10. $filelist=array();
11. while ($file = readdir($handle))
12. {
13. if($file<>"." and $file<>"..")
14. {
15. if(is_dir($file))
16. {
17. $dirlist[] = $file;
18. }
19. else
20. {
21. $filelist[] = $directory.DIRECTORY_SEPARATOR.$file;
22. }
23. }
24.
25.
26. }
27. closedir($handle);
28. return $filelist;
29. }
30.
31. function display_filename($filename)
32. {
33. $i=strrpos($filename,DIRECTORY_SEPARATOR);
34. $tmp=substr($filename,$i+1);
35. return $tmp;
36. }
37.
38.
39. function display_fileencoding($filename)
40. {
41. if(extension_loaded("mbsting"))
42. {
43. $code=mb_detect_encoding($filename);
44. $filename=mb_convert_encoding($filename,"UTF-8",$code);
45. return $filename;
46. }
47. else
48. die("请检查系统是否正确安装配置mbstring");
49. }
50.
51. function display_file($filename)
52. {
53. return $dirperm=substr(base_convert(fileperms($filename),10,8),-4);
54. }
55.
56. function display_size($file)
57. {
58. $file_size = filesize($file);
59. if($file_size >= 1073741824)
60. {
61. $file_size = round($file_size / 1073741824 * 100) / 100 . "Gb";
62. }
63. elseif($file_size >= 1048576)
64. {
65. $file_size = round($file_size / 1048576 * 100) / 100 . "Mb";
66. }
67. elseif($file_size >= 1024)
68. {
69. $file_size = round($file_size / 1024 * 100) / 100 . "Kb";
70. }
71. else{
72. $file_size = $file_size . "B";
73. }
74. return $file_size;
75. }
76.
77. function display_ctime($file)
78. {
79. date_default_timezone_set("PRC");
80. $changeddate = date("Y-m-d H:i:s",filectime($file));
81. return $changeddate;
82. }
83.
84. function display_mtime($filename)
85. {
86. date_default_timezone_set("PRC");
87. return $mtime=date("Y-m-d H:i:s",filemtime($filename));
88. return $mtime;
89. }
90.
91. function display_mtime($filename)
92. {
93. date_default_timezone_set("PRC");
94. return $mtime=date("Y-m-d H:i:s",fileatime($filename));
95. return $mtime;
96. }
97.
98.
99. function display_filetype($file)
100. {
101. $path="./images";
102.
103.
104. if (eregi(".bmp|.jpg|.jpeg",$file))
105. {
106. $icon = "<IMG SRC="$path/image.gif" mce_SRC="$path/image.gif" alt=\"图片\" border=\"0\">";
107. }
108.
109. if (eregi(".pdf",$file))
110. {
111. $icon = "<IMG SRC="$path/PDFXP.ico" mce_SRC="$path/PDFXP.ico" alt=\"PDF文件\" border=\"0\">";
112. }
113.
114. elseif (eregi(".txt",$file))
115. {
116. $icon = "<IMG SRC="$path/TEXT.GIF" mce_SRC="$path/TEXT.GIF" alt=\" 文本文件\" border=\"0\">";
117. }
118.
119. elseif (eregi(".wav|.mp2|.mp3|.mp4|.vqf|.midi|.wmv",$file))
120. {
121. $icon = "<IMG SRC="$path/WMPDOCUMENT.ico" mce_SRC="$path/WMPDOCUMENT.ico" alt=\"Audio\" border=\"0\">";
122. }
123.
124. elseif (eregi(".ppt",$file))
125. {
126. $icon = "<IMG SRC="$path/PPT.ico" mce_SRC="$path/PPT.ico" alt=\"PPT\" border=\"0\">";
127. }
128.
129. elseif (eregi(".rar|.tar.gz|.7z",$file))
130. {
131. $icon = "<IMG SRC="$path/RARICON.ico" mce_SRC="$path/RARICON.ico" alt=\"RAR\" border=\"0\">";
132. }
133.
134. elseif (eregi(".phps|.php|.php2|.php3|.php4|.asp|.asa|.cgi|.pl|.shtml",$file))
135. {
136. $icon = "<IMG SRC="$path/PHP.ico" mce_SRC="$path/PHP.ico" alt=\"PHP\" border=\"0\">";
137. }
138.
139. elseif (eregi(".htaccess",$file))
140. {
141. $icon = "<IMG SRC="$path/security.gif" mce_SRC="$path/security.gif" alt=\"Apache Webserver security settings\" border=\"0\">" ;
142. }
143.
144. elseif (eregi(".html|.htm",$file))
145. {
146. $icon = "<IMG SRC="$path/WEBPAGE.GIF" mce_SRC="$path/WEBPAGE.GIF" alt=\" 网页文件\" border=\"0\">";
147. }
148.
149. else
150. {
151. $icon = "<IMG SRC="$path/DEFAULT.ico" mce_SRC="$path/DEFAULT.ico" alt=\" 未知文件类型\" border=\"0\">";
152. }
153. return $icon;
154. }
155.
156. function copydir($dirFrom,$dirTo)
157. {
158. $filecounter=0;
159. $dircounter=0;
160. if(is_file($dirTo))
161. {
162. die("无法创建目录 $dirTo");
163. }
164. if(!file_exists($dirTo))
165. {
166. mkdir($dirTo);
167. $dircounter++;
168. }
169. $handle=@opendir($dirFrom);
170. while(($file=readdir($handle))!==false)
171. {
172. if($file<>"." and $file<>"..")
173. {
174. $fileFrom=$dirFrom.DIRECTORY_SEPARATOR.$file;
175. $fileTo=$dirTo.DIRECTORY_SEPARATOR.$file;
176. if(is_dir($fileFrom))
177. {
178. copydir($fileFrom,$fileTo);
179. }
180. else
181. {
182. copy($fileFrom,$fileTo);
183. $filecounter++;
184. }
185. }
186.
187. }
188. closedir($handle);
189. }
190.
191. function deleteDir($pathName)
192. {
193. $handle=@opendir($pathName);
194. while(($file=readdir($handle))!==false)
195. {
196. if($file<>"." and $file<>"..")
197. {
198. $file=$pathName.DIRECTORY_SEPARATOR.$file;
199. if(is_dir($file))
200. {
201. deleteDir($file);
202. }
203. else
204. {
205. if(unlink($file))
206. {
207. echo "文件",$file."删除成功<br>";
208. }
209. else
210. {
211. echo "文件",$file."删除失败<br>";
212. }
213. }
214. }
215.
216. }
217. closedir($handle);
218.
219. if(rmdir($pathName))
220. {
221. echo "目录<b>".$pathName."</b>删除成功<br>";
222. }
223. else
224. {
225. echo "目录<b>".$pathName."</b>删除失败<br>";
226. }
227.
228. }
229.
230. function delFile($filename)
231. {
232. @copy("../personalmanager/upload/".$filename,"../personalmanager/backupdel/".$filename);
233. @unlink("../personalmanager/upload/".$filename);
234. }
235. function fileUpload()
236. {
237. $uploaddir="upload/";
238. for($i=0;$i<count($_FILES["myfile"]["name"]);$i++)
239. {
240. if($_FILES["myfile"]["size"][$i]>=40000)
241. {
242. echo $_FILES["myfile"]["name"][$i]."文件太大<br>";
243. continue;
244. }
245.
257. if(move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$uploaddir.$_FILES["myfile"]["name"][$i]))
258. {
259. echo "<mce:script language='javascript'><!--
260. alert('文件上传成功');
261.
262.
263. ";
264. }
265. }
266. }
267. }
268.
269. ?>