fileChajian.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <?php
  2. class fileChajian extends Chajian
  3. {
  4. public $path; //文件路径
  5. public $name; //文件名称
  6. public $ext; //扩展名
  7. private $mimitype = array(
  8. 'unkown' => 'application/octet-stream',
  9. 'acx' => 'application/internet-property-stream',
  10. 'ai' => 'application/postscript',
  11. 'aif' => 'audio/x-aiff',
  12. 'aifc' => 'audio/x-aiff',
  13. 'aiff' => 'audio/x-aiff',
  14. 'asp' => 'text/plain',
  15. 'aspx' => 'text/plain',
  16. 'asf' => 'video/x-ms-asf',
  17. 'asr' => 'video/x-ms-asf',
  18. 'asx' => 'video/x-ms-asf',
  19. 'au' => 'audio/basic',
  20. 'avi' => 'video/x-msvideo',
  21. 'axs' => 'application/olescript',
  22. 'bas' => 'text/plain',
  23. 'bcpio' => 'application/x-bcpio',
  24. 'bin' => 'application/octet-stream',
  25. 'bmp' => 'image/bmp',
  26. 'c' => 'text/plain',
  27. 'cat' => 'application/vnd.ms-pkiseccat',
  28. 'cdf' => 'application/x-cdf',
  29. 'cer' => 'application/x-x509-ca-cert',
  30. 'class' => 'application/octet-stream',
  31. 'clp' => 'application/x-msclip',
  32. 'cmx' => 'image/x-cmx',
  33. 'cod' => 'image/cis-cod',
  34. 'cpio' => 'application/x-cpio',
  35. 'crd' => 'application/x-mscardfile',
  36. 'crl' => 'application/pkix-crl',
  37. 'crt' => 'application/x-x509-ca-cert',
  38. 'csh' => 'application/x-csh',
  39. 'css' => 'text/css',
  40. 'dcr' => 'application/x-director',
  41. 'der' => 'application/x-x509-ca-cert',
  42. 'dir' => 'application/x-director',
  43. 'dll' => 'application/x-msdownload',
  44. 'dms' => 'application/octet-stream',
  45. 'doc' => 'application/msword',
  46. 'docx' => 'application/msword',
  47. 'dot' => 'application/msword',
  48. 'dvi' => 'application/x-dvi',
  49. 'dxr' => 'application/x-director',
  50. 'eps' => 'application/postscript',
  51. 'etx' => 'text/x-setext',
  52. 'evy' => 'application/envoy',
  53. 'exe' => 'application/octet-stream',
  54. 'fif' => 'application/fractals',
  55. 'flr' => 'x-world/x-vrml',
  56. 'flv' => 'video/x-flv',
  57. 'gif' => 'image/gif',
  58. 'gtar' => 'application/x-gtar',
  59. 'gz' => 'application/x-gzip',
  60. 'h' => 'text/plain',
  61. 'hdf' => 'application/x-hdf',
  62. 'hlp' => 'application/winhlp',
  63. 'hqx' => 'application/mac-binhex40',
  64. 'hta' => 'application/hta',
  65. 'htc' => 'text/x-component',
  66. 'htm' => 'text/html',
  67. 'html' => 'text/html',
  68. 'shtml' => 'text/html',
  69. 'htt' => 'text/webviewhtml',
  70. 'ico' => 'image/x-icon',
  71. 'ief' => 'image/ief',
  72. 'iii' => 'application/x-iphone',
  73. 'ins' => 'application/x-internet-signup',
  74. 'isp' => 'application/x-internet-signup',
  75. 'jfif' => 'image/pipeg',
  76. 'jpe' => 'image/jpeg',
  77. 'jpeg' => 'image/jpeg',
  78. 'jpg' => 'image/jpeg',
  79. 'js' => 'application/x-javascript',
  80. 'latex' => 'application/x-latex',
  81. 'lha' => 'application/octet-stream',
  82. 'lsf' => 'video/x-la-asf',
  83. 'lsx' => 'video/x-la-asf',
  84. 'lzh' => 'application/octet-stream',
  85. 'm13' => 'application/x-msmediaview',
  86. 'm14' => 'application/x-msmediaview',
  87. 'm3u' => 'audio/x-mpegurl',
  88. 'man' => 'application/x-troff-man',
  89. 'mdb' => 'application/x-msaccess',
  90. 'me' => 'application/x-troff-me',
  91. 'mht' => 'message/rfc822',
  92. 'mhtml' => 'message/rfc822',
  93. 'mid' => 'audio/mid',
  94. 'mny' => 'application/x-msmoney',
  95. 'mov' => 'video/quicktime',
  96. 'movie' => 'video/x-sgi-movie',
  97. 'mp2' => 'video/mpeg',
  98. 'mp3' => 'audio/mpeg',
  99. 'mpa' => 'video/mpeg',
  100. 'mpe' => 'video/mpeg',
  101. 'mpeg' => 'video/mpeg',
  102. 'mpg' => 'video/mpeg',
  103. 'mpp' => 'application/vnd.ms-project',
  104. 'mpv2' => 'video/mpeg',
  105. 'ms' => 'application/x-troff-ms',
  106. 'mvb' => 'application/x-msmediaview',
  107. 'nws' => 'message/rfc822',
  108. 'oda' => 'application/oda',
  109. 'p10' => 'application/pkcs10',
  110. 'p12' => 'application/x-pkcs12',
  111. 'p7b' => 'application/x-pkcs7-certificates',
  112. 'p7c' => 'application/x-pkcs7-mime',
  113. 'p7m' => 'application/x-pkcs7-mime',
  114. 'p7r' => 'application/x-pkcs7-certreqresp',
  115. 'p7s' => 'application/x-pkcs7-signature',
  116. 'pbm' => 'image/x-portable-bitmap',
  117. 'pdf' => 'application/pdf',
  118. 'pfx' => 'application/x-pkcs12',
  119. 'pgm' => 'image/x-portable-graymap',
  120. 'pko' => 'application/ynd.ms-pkipko',
  121. 'pma' => 'application/x-perfmon',
  122. 'pmc' => 'application/x-perfmon',
  123. 'pml' => 'application/x-perfmon',
  124. 'pmr' => 'application/x-perfmon',
  125. 'pmw' => 'application/x-perfmon',
  126. 'png' => 'image/png',
  127. 'pnm' => 'image/x-portable-anymap',
  128. 'pot,' => 'application/vnd.ms-powerpoint',
  129. 'ppm' => 'image/x-portable-pixmap',
  130. 'pps' => 'application/vnd.ms-powerpoint',
  131. 'ppt' => 'application/vnd.ms-powerpoint',
  132. 'pptx' => 'application/vnd.ms-powerpoint',
  133. 'prf' => 'application/pics-rules',
  134. 'ps' => 'application/postscript',
  135. 'pub' => 'application/x-mspublisher',
  136. 'qt' => 'video/quicktime',
  137. 'ra' => 'audio/x-pn-realaudio',
  138. 'ram' => 'audio/x-pn-realaudio',
  139. 'ras' => 'image/x-cmu-raster',
  140. 'rgb' => 'image/x-rgb',
  141. 'rmi' => 'audio/mid',
  142. 'roff' => 'application/x-troff',
  143. 'rtf' => 'application/rtf',
  144. 'rtx' => 'text/richtext',
  145. 'scd' => 'application/x-msschedule',
  146. 'sct' => 'text/scriptlet',
  147. 'setpay' => 'application/set-payment-initiation',
  148. 'setreg' => 'application/set-registration-initiation',
  149. 'sh' => 'application/x-sh',
  150. 'shar' => 'application/x-shar',
  151. 'sit' => 'application/x-stuffit',
  152. 'snd' => 'audio/basic',
  153. 'spc' => 'application/x-pkcs7-certificates',
  154. 'spl' => 'application/futuresplash',
  155. 'src' => 'application/x-wais-source',
  156. 'sst' => 'application/vnd.ms-pkicertstore',
  157. 'stl' => 'application/vnd.ms-pkistl',
  158. 'stm' => 'text/html',
  159. 'svg' => 'image/svg+xml',
  160. 'sv4cpio' => 'application/x-sv4cpio',
  161. 'sv4crc' => 'application/x-sv4crc',
  162. 'swf' => 'application/x-shockwave-flash',
  163. 't' => 'application/x-troff',
  164. 'tar' => 'application/x-tar',
  165. 'tcl' => 'application/x-tcl',
  166. 'tex' => 'application/x-tex',
  167. 'texi' => 'application/x-texinfo',
  168. 'texinfo' => 'application/x-texinfo',
  169. 'tgz' => 'application/x-compressed',
  170. 'tif' => 'image/tiff',
  171. 'tiff' => 'image/tiff',
  172. 'tr' => 'application/x-troff',
  173. 'trm' => 'application/x-msterminal',
  174. 'tsv' => 'text/tab-separated-values',
  175. 'txt' => 'text/plain',
  176. 'uls' => 'text/iuls',
  177. 'ustar' => 'application/x-ustar',
  178. 'vcf' => 'text/x-vcard',
  179. 'vrml' => 'x-world/x-vrml',
  180. 'wav' => 'audio/x-wav',
  181. 'wcm' => 'application/vnd.ms-works',
  182. 'wdb' => 'application/vnd.ms-works',
  183. 'wks' => 'application/vnd.ms-works',
  184. 'wmf' => 'application/x-msmetafile',
  185. 'wmv' => 'video/x-ms-wmv',
  186. 'wps' => 'application/vnd.ms-works',
  187. 'wri' => 'application/x-mswrite',
  188. 'wrl' => 'x-world/x-vrml',
  189. 'wrz' => 'x-world/x-vrml',
  190. 'xaf' => 'x-world/x-vrml',
  191. 'xbm' => 'image/x-xbitmap',
  192. 'xla' => 'application/vnd.ms-excel',
  193. 'xlc' => 'application/vnd.ms-excel',
  194. 'xlm' => 'application/vnd.ms-excel',
  195. 'xls' => 'application/vnd.ms-excel',
  196. 'xlsx' => 'application/vnd.ms-excel',
  197. 'xlt' => 'application/vnd.ms-excel',
  198. 'xlw' => 'application/vnd.ms-excel',
  199. 'xof' => 'x-world/x-vrml',
  200. 'xpm' => 'image/x-xpixmap',
  201. 'xwd' => 'image/x-xwindowdump',
  202. 'z' => 'application/x-compress',
  203. 'zip' => 'application/zip',
  204. 'rar' => 'application/zip',
  205. 'php' => 'text/x-php',
  206. );
  207. public function getAllMime()
  208. {
  209. return $this->mimitype;
  210. }
  211. /**
  212. 文件信息
  213. */
  214. public function fileinfo($path)
  215. {
  216. if($this->filebool($path)){
  217. $arr=pathinfo($path);
  218. $this->name = $arr['basename'];
  219. $this->path = $arr['dirname'];
  220. $this->ext = $arr['extension'];
  221. }
  222. }
  223. /**
  224. 删除文件
  225. */
  226. public function delfile($file)
  227. {
  228. $bool = false;
  229. if($this->filebool($file)){
  230. $bool = unlink($file);
  231. }
  232. return $bool;
  233. }
  234. /**
  235. 重命名
  236. */
  237. public function rename($oldf,$newf)
  238. {
  239. $bool = false;
  240. if($this->filebool($oldf)){
  241. $bool = rename($oldf,$newf);
  242. }
  243. return $bool;
  244. }
  245. /**
  246. 判断文件是否存在
  247. */
  248. public function filebool($path)
  249. {
  250. return file_exists($path);
  251. }
  252. /**
  253. 创建文件
  254. @pamars $path 文件路径
  255. @pamars $cont 内容
  256. */
  257. public function caretefile($path,$cont)
  258. {
  259. }
  260. public function createdir($path, $oi=1)
  261. {
  262. $zpath = explode('/', $path);
  263. $len = count($zpath);
  264. $mkdir = '';
  265. for($i=0; $i<$len-$oi; $i++){
  266. if(!$this->isempt($zpath[$i])){
  267. $mkdir.='/'.$zpath[$i].'';
  268. $wzdir = ROOT_PATH.''.$mkdir;
  269. if(!is_dir($wzdir)){
  270. mkdir($wzdir);
  271. }
  272. }
  273. }
  274. }
  275. /**
  276. * 获取某个目录下所有文件
  277. */
  278. public function getfilerows($path)
  279. {
  280. $rows = array();
  281. if(!is_dir($path))return $rows;
  282. @$d = opendir($path);
  283. $nyunf = array('.', '..');
  284. while( false !== ($file = readdir($d))){
  285. if(!in_array($file, $nyunf)){
  286. $filess = $path.'/'.$file;
  287. if(is_file($filess)){
  288. $editdt = filectime($filess);//上次修改时间
  289. $lastdt = filemtime($filess);//最后修改的时间
  290. $rows[] = array(
  291. 'filename' => $file,
  292. 'editdt' => date('Y-m-d H:i:s', $editdt),
  293. 'lastdt' => date('Y-m-d H:i:s', $lastdt),
  294. );
  295. }
  296. }
  297. }
  298. return $rows;
  299. }
  300. /**
  301. * 获取某个目录下所有文件夹
  302. */
  303. public function getfolderrows($path)
  304. {
  305. $rows = array();
  306. if(!is_dir($path))return $rows;
  307. @$d = opendir($path);
  308. $nyunf = array('.', '..');
  309. while( false !== ($file = readdir($d))){
  310. if(!in_array($file, $nyunf)){
  311. $filess = $path.'/'.$file;
  312. if(is_dir($filess)){
  313. $rows[] = array(
  314. 'filename' => $file,
  315. );
  316. }
  317. }
  318. }
  319. return $rows;
  320. }
  321. /**
  322. * 获取文件的mime类型
  323. */
  324. public function getMime($file)
  325. {
  326. $mime = '';
  327. if(!file_exists($file))return $mime;
  328. if(class_exists('finfo')){
  329. $fi = new finfo(FILEINFO_MIME_TYPE);
  330. $mime = $fi->file($file);
  331. }else{
  332. $fobj = getimagesize($file);
  333. $mime = strtolower($fobj['mime']);
  334. }
  335. return $mime;
  336. }
  337. /**
  338. * 根据文件获取对应扩展名
  339. */
  340. public function getfiletoExt($file, $ext='')
  341. {
  342. $mime = $this->getMime($file);
  343. if($mime=='')return $ext;
  344. foreach($this->mimitype as $kz=>$mita){
  345. if($mita == $mime){
  346. $ext = $kz;
  347. break;
  348. }
  349. }
  350. return $ext;
  351. }
  352. }
粤ICP备19079148号