Core.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?php
  2. namespace Upload\Lib\Store;
  3. use Dever;
  4. use Dever\String\Helper as Helper;
  5. use Dever\Loader\Config;
  6. use Dever\Support\Img;
  7. class Core
  8. {
  9. protected $data;
  10. protected $config;
  11. protected $handle;
  12. protected $img;
  13. protected $output;
  14. protected $limit;
  15. protected $name;
  16. protected $path;
  17. protected $ext = '';
  18. protected $file;
  19. protected $size;
  20. protected $base = '';
  21. protected $base64 = false;
  22. protected $yun = false;
  23. protected $id = false;
  24. /**
  25. * __construct
  26. *
  27. * @return mixed
  28. */
  29. public function __construct($data = array())
  30. {
  31. $this->data = $data;
  32. }
  33. public function getData()
  34. {
  35. return $this->data;
  36. }
  37. /**
  38. * 获取根目录
  39. *
  40. * @return mixed
  41. */
  42. protected function root()
  43. {
  44. if (!$this->base) {
  45. $path = Config::data();
  46. $this->base = Dever::path($path . 'upload/');
  47. }
  48. return $this->base;
  49. }
  50. /**
  51. * 验证数据
  52. *
  53. * @return mixed
  54. */
  55. private function check($param)
  56. {
  57. foreach ($param as $k => $v) {
  58. $method = 'check_' . $v;
  59. $this->$method();
  60. if ($this->output['status'] == -1) {
  61. break;
  62. }
  63. }
  64. }
  65. /**
  66. * 验证key是否包含有后续处理的方法
  67. *
  68. * @return mixed
  69. */
  70. private function check_handle()
  71. {
  72. if (isset($this->data['key']) && strpos($this->data['key'], '_') !== false) {
  73. $temp = explode('_', $this->data['key']);
  74. $this->data['key'] = $temp[0];
  75. unset($temp[0]);
  76. foreach ($temp as $k => $v) {
  77. $this->handle[] = explode('=', $v);
  78. }
  79. }
  80. }
  81. /**
  82. * 验证文件是否存在
  83. *
  84. * @return mixed
  85. */
  86. private function check_file()
  87. {
  88. if ($this->data['file']['tmp_name'] == '') {
  89. $this->output['status'] = -1;
  90. $this->output['message'] = '没有选择文件';
  91. }
  92. }
  93. /**
  94. * 验证基本配置
  95. *
  96. * @return mixed
  97. */
  98. private function check_key()
  99. {
  100. if (trim($this->data['key']) == '') {
  101. $this->output['status'] = -1;
  102. $this->output['message'] = '请添加配置key';
  103. } else {
  104. $this->config = Dever::load('upload/upload-one', $this->data['key']);
  105. if (!$this->config) {
  106. $this->output['status'] = -1;
  107. $this->output['message'] = '此配置不存在';
  108. }
  109. }
  110. }
  111. /**
  112. * 验证文件类型
  113. *
  114. * @return mixed
  115. */
  116. private function check_type()
  117. {
  118. if (!$this->ext) {
  119. $ext = $this->getExt($this->data['file']['tmp_name']);
  120. if (strpos($this->config['type'], $ext) === false) {
  121. $this->output['status'] = -1;
  122. $this->output['message'] = '文件格式不符合要求';
  123. }
  124. $this->ext = '.' . $ext;
  125. }
  126. }
  127. /**
  128. * 验证文件大小
  129. *
  130. * @return mixed
  131. */
  132. private function check_size()
  133. {
  134. if (!$this->limit) {
  135. $this->limit = getimagesize($this->data['file']['tmp_name']);
  136. }
  137. # 默认30M
  138. $size = $this->config['size'] > 0 ? 1024*1024*$this->config['size'] : 30*1024*1024;
  139. if (isset($this->data['file']['size'])) {
  140. $this->size = $this->data['file']['size'];
  141. if (($size < $this->data['file']['size']) && $size > 0) {
  142. $this->output['status'] = -1;
  143. $this->output['message'] = '文件不能超过'.(($size/1024)/1024).'MB';
  144. } elseif ($this->config['width'] > 0 && $this->config['width'] < $this->limit[0]) {
  145. $this->output['status'] = -1;
  146. $this->output['message'] = '图片宽度不能超过' . $this->config['width'] . 'px';
  147. } elseif ($this->config['height'] > 0 && $this->config['height'] < $this->limit[1]) {
  148. $this->output['status'] = -1;
  149. $this->output['message'] = '图片高度不能超过' . $this->config['height'] . 'px';
  150. }
  151. $this->size = number_format($this->size/1024, 2);
  152. }
  153. }
  154. /**
  155. * 上传操作
  156. *
  157. * @return mixed
  158. */
  159. public function copy()
  160. {
  161. $this->output['status'] = 1;
  162. if (is_string($this->data['file'])) {
  163. if (strstr($this->data['file'], 'base64,') && isset($this->data['pic'])) {
  164. $temp = explode('base64,', $this->data['file']);
  165. $type = str_replace(array('data:', ';'), '', $temp[0]);
  166. $file = str_replace(' ', '+', $temp[1]);
  167. $file = str_replace('=', '', $temp[1]);
  168. $file = base64_decode($file);
  169. $name = $this->data['local'] = Dever::local($this->data['pic']);
  170. $size = strlen($file);
  171. $size = number_format(($size - ($size/8)*2)/1024, 2);
  172. $this->base64 = true;
  173. } else {
  174. $name = urldecode($this->data['file']);
  175. }
  176. $this->data['file'] = array();
  177. if (((isset($this->data['cropper']) && !$this->yun) || !isset($this->data['cropper'])) && strstr($name, 'http')) {
  178. $this->base64 = false;
  179. $this->root();
  180. header('Content-type: text/json; charset=utf-8');
  181. $path = Dever::path($this->base, 'tmp/');
  182. $ext = $name;
  183. if (strstr($name, '?')) {
  184. $temp = explode('?', $ext);
  185. $ext = $temp[0];
  186. }
  187. $this->ext = '.' . pathinfo($ext, PATHINFO_EXTENSION);
  188. $this->data['file']['name'] = 'Tmp' . sha1($name);
  189. $this->data['file']['tmp_name'] = $path . $this->data['file']['name'];
  190. if (!is_file($this->data['file']['tmp_name'])) {
  191. if (strstr($name, 'tp=webp')) {
  192. $name = str_replace('tp=webp', 'tp=jpeg', $name);
  193. } elseif (strstr($name, '.webp')) {
  194. $name = str_replace('.webp', '.jpg', $name);
  195. }
  196. if (!isset($file)) {
  197. $file = Dever::curl($name);
  198. }
  199. if (stristr($file, 'webp')) {
  200. # 将webp图片转成jpg
  201. $this->ext = '.jpg';
  202. }
  203. if (!isset($file)) {
  204. Dever::alert('错误的文件来源');
  205. }
  206. file_put_contents($this->data['file']['tmp_name'], $file);
  207. }
  208. $this->data['file']['size'] = filesize($this->data['file']['tmp_name']);
  209. } elseif (isset($file)) {
  210. $this->data['file']['name'] = $name;
  211. $this->data['file']['tmp_name'] = $file;
  212. } else {
  213. $this->data['file']['name'] = $name;
  214. $this->data['file']['tmp_name'] = $name;
  215. }
  216. if (isset($type)) {
  217. $this->data['file']['type'] = $type;
  218. }
  219. if (isset($size)) {
  220. $this->data['file']['size'] = $size;
  221. }
  222. if (isset($this->data['param'])) {
  223. $this->limit = array($this->data['param']['param_w'], $this->data['param']['param_h']);
  224. if (isset($this->data['name'])) {
  225. $param = implode('_', array_values($this->data['param']));
  226. $this->data['file']['name'] = '.' . $this->data['name'] . $param;
  227. if ($this->base64) {
  228. $this->data['name'] = $this->data['file']['name'];
  229. } else {
  230. $filename = md5($this->data['pic']) . '.' . pathinfo($this->data['pic'], PATHINFO_EXTENSION);
  231. $this->path();
  232. $file = $this->base . $this->data['key'] . $this->path . $filename;
  233. if (!is_file($file)) {
  234. $content = Dever::curl($name);
  235. file_put_contents($file, $content);
  236. }
  237. $this->data['name'] = $filename . $this->data['file']['name'];
  238. }
  239. $this->ext = '.jpg';
  240. }
  241. }
  242. } else {
  243. header("Content-type: application/json; charset=utf-8");
  244. }
  245. $this->check(array('handle', 'file', 'key', 'type', 'size'));
  246. if ($this->output['status'] == -1) {
  247. $this->delete();
  248. return $this->output;
  249. }
  250. $this->save();
  251. if ($this->output['status'] == -1) {
  252. return $this->output;
  253. }
  254. if (isset($this->handle) && is_array($this->handle)) {
  255. foreach ($this->handle as $k => $v) {
  256. $method = 'handle_' . $v[0];
  257. if (method_exists($this, $method)) {
  258. $this->$method($v);
  259. }
  260. $this->$method($v[1]);
  261. }
  262. } elseif (isset($this->config['alter']) && $this->config['alter']) {
  263. parse_str($this->config['alter'], $handle);
  264. if ($handle) {
  265. foreach ($handle as $k => $v) {
  266. $method = 'handle_' . $k;
  267. if (method_exists($this, $method)) {
  268. $this->$method($v);
  269. }
  270. }
  271. }
  272. }
  273. $this->output['uploaded'] = true;
  274. $this->output['status'] = 1;
  275. $this->output['name'] = $this->data['file']['name'];
  276. $this->output['fid'] = $this->id;
  277. if ($this->limit) {
  278. $this->output['width'] = $this->limit[0];
  279. $this->output['height'] = $this->limit[1];
  280. }
  281. if ($this->size) {
  282. $this->output['size'] = $this->size;
  283. }
  284. return $this->output;
  285. }
  286. protected function update($id)
  287. {
  288. $param['set_name'] = $this->name;
  289. $param['set_source_name'] = $this->data['file']['name'];
  290. $param['set_file'] = $this->file;
  291. $param['set_key'] = md5($this->output['url']);
  292. $param['set_ext'] = $this->ext;
  293. if (isset($this->data['cate'])) {
  294. $param['set_cate'] = $this->data['cate'];
  295. }
  296. if ($this->limit) {
  297. $param['set_width'] = $this->limit[0];
  298. $param['set_height'] = $this->limit[1];
  299. }
  300. if ($this->size) {
  301. $param['set_size'] = $this->size;
  302. }
  303. if (isset($this->data['search']) && $this->data['search']) {
  304. $param['search'] = $this->data['search'];
  305. }
  306. $this->id = $param['where_id'] = $id;
  307. Dever::db('upload/file')->update($param);
  308. }
  309. protected function insert()
  310. {
  311. $param['add_name'] = $this->name;
  312. $param['add_source_name'] = $this->data['file']['name'];
  313. $param['add_file'] = $this->file;
  314. $param['add_key'] = md5($this->output['url']);
  315. $param['add_ext'] = $this->ext;
  316. $param['add_upload'] = $this->data['key'];
  317. if (isset($this->data['cate'])) {
  318. $param['add_cate'] = $this->data['cate'];
  319. }
  320. if ($this->limit) {
  321. $param['add_width'] = $this->limit[0];
  322. $param['add_height'] = $this->limit[1];
  323. }
  324. if ($this->size) {
  325. $param['add_size'] = $this->size;
  326. }
  327. $param['add_state'] = 1;
  328. //file_put_contents(DEVER_PATH . 'data/test', var_export($param,true));
  329. if (isset($this->data['search']) && $this->data['search']) {
  330. $param['search'] = $this->data['search'];
  331. }
  332. $this->id = Dever::db('upload/file')->insert($param);
  333. }
  334. protected function img()
  335. {
  336. $this->img = isset($this->img) ? $this->img : new Img();
  337. $this->img->setType('im');
  338. return $this->img;
  339. }
  340. protected function getName()
  341. {
  342. $this->path()->name($this->data['file']['name'])->ext()->file();
  343. }
  344. protected function path()
  345. {
  346. $date = explode('-', date("Y-m-d"));
  347. $this->path = $this->config['id'] . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
  348. return $this;
  349. }
  350. protected function name($name)
  351. {
  352. if (isset($this->data['name'])) {
  353. $this->name = $this->data['name'];
  354. } else {
  355. $this->name = md5($name);
  356. }
  357. return $this;
  358. }
  359. protected function ext()
  360. {
  361. $this->ext = $this->ext ? $this->ext : '.' . pathinfo($this->data['file']['name'], PATHINFO_EXTENSION);
  362. if ($this->ext == '.') {
  363. $this->ext = '.jpg';
  364. }
  365. return $this;
  366. }
  367. /**
  368. * getExt
  369. *
  370. * @return mixed
  371. */
  372. protected function getExt($filename)
  373. {
  374. if (isset($this->data['file']['type'])) {
  375. $ext = $this->getExtByMine($this->data['file']['type']);
  376. } elseif (function_exists('finfo_open')) {
  377. $finfo = finfo_open(FILEINFO_MIME); // 返回 mime 类型
  378. $code = finfo_file($finfo, $filename);
  379. finfo_close($finfo);
  380. $temp = explode(';', $code);
  381. $ext = $this->getExtByMine($temp[0]);
  382. } else {
  383. $ext = $this->getExtByByte($filename);
  384. }
  385. if (!$ext || $ext == 'txt' || $ext == 'exe') {
  386. if (isset($this->data['file']['type'])) {
  387. $ext = $this->getExtByMine($this->data['file']['type']);
  388. }
  389. if (!$ext || $ext == 'txt' || $ext == 'exe') {
  390. $ext = $this->getExtByByte($filename);
  391. }
  392. }
  393. return $ext;
  394. }
  395. public function delete()
  396. {
  397. @unlink($this->data['file']['tmp_name']);
  398. }
  399. /**
  400. * 根据mime类型获取文件扩展名
  401. *
  402. * @return mixed
  403. */
  404. protected function getExtByMine($mine)
  405. {
  406. $mine = trim($mine);
  407. $config = array
  408. (
  409. 'application/envoy' => 'evy',
  410. 'application/fractals' => 'fif',
  411. 'application/futuresplash' => 'spl',
  412. 'application/hta' => 'hta',
  413. 'application/internet-property-stream' => 'acx',
  414. 'application/mac-binhex40' => 'hqx',
  415. 'application/msword' => 'doc',
  416. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
  417. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
  418. 'video/x-m4v' => 'mp4',
  419. 'video/mp4' => 'mp4',
  420. 'application/octet-stream' => 'exe',
  421. 'application/oda' => 'oda',
  422. 'application/olescript' => 'axs',
  423. 'application/pdf' => 'pdf',
  424. 'application/pics-rules' => 'prf',
  425. 'application/pkcs10' => 'p10',
  426. 'application/pkix-crl' => 'crl',
  427. 'application/postscript' => 'ai',
  428. 'application/postscript' => 'eps',
  429. 'application/postscript' => 'ps',
  430. 'application/rtf' => 'rtf',
  431. 'application/set-payment-initiation' => 'setpay',
  432. 'application/set-registration-initiation' => 'setreg',
  433. 'application/vnd.ms-excel' => 'xls',
  434. 'application/vnd.ms-outlook' => 'msg',
  435. 'application/vnd.ms-pkicertstore' => 'sst',
  436. 'application/vnd.ms-pkiseccat' => 'cat',
  437. 'application/vnd.ms-pkistl' => 'stl',
  438. 'application/vnd.ms-powerpoint' => 'ppt',
  439. 'application/vnd.ms-project' => 'mpp',
  440. 'application/vnd.ms-works' => 'wps',
  441. 'application/winhlp' => 'hlp',
  442. 'application/x-bcpio' => 'bcpio',
  443. 'application/x-cdf' => 'cdf',
  444. 'application/x-compress' => 'z',
  445. 'application/x-compressed' => 'tgz',
  446. 'application/x-cpio' => 'cpio',
  447. 'application/x-csh' => 'csh',
  448. 'application/x-director' => 'dir',
  449. 'application/x-dvi' => 'dvi',
  450. 'application/x-gtar' => 'gtar',
  451. 'application/x-gzip' => 'gz',
  452. 'application/x-hdf' => 'hdf',
  453. 'application/x-internet-signup' => 'isp',
  454. 'application/x-iphone' => 'iii',
  455. 'application/x-javascript' => 'js',
  456. 'application/x-latex' => 'latex',
  457. 'application/x-msaccess' => 'mdb',
  458. 'application/x-mscardfile' => 'crd',
  459. 'application/x-msclip' => 'clp',
  460. 'application/x-msdownload' => 'dll',
  461. 'application/x-msmediaview' => 'mvb',
  462. 'application/x-msmetafile' => 'wmf',
  463. 'application/x-msmoney' => 'mny',
  464. 'application/x-mspublisher' => 'pub',
  465. 'application/x-msschedule' => 'scd',
  466. 'application/x-msterminal' => 'trm',
  467. 'application/x-mswrite' => 'wri',
  468. 'application/x-netcdf' => 'cdf',
  469. 'application/x-netcdf' => 'nc',
  470. 'application/x-perfmon' => 'pma',
  471. 'application/x-pkcs12' => 'p12',
  472. 'application/x-pkcs12' => 'pfx',
  473. 'application/x-pkcs7-certificates' => 'p7b',
  474. 'application/x-pkcs7-certreqresp' => 'p7r',
  475. 'application/x-pkcs7-mime' => 'p7c',
  476. 'application/x-pkcs7-signature' => 'p7s',
  477. 'application/x-sh' => 'sh',
  478. 'application/x-shar' => 'shar',
  479. 'application/x-shockwave-flash' => 'swf',
  480. 'application/x-stuffit' => 'sit',
  481. 'application/x-sv4cpio' => 'sv4cpio',
  482. 'application/x-sv4crc' => 'sv4crc',
  483. 'application/x-tar' => 'tar',
  484. 'application/x-tcl' => 'tcl',
  485. 'application/x-tex' => 'tex',
  486. 'application/x-texinfo' => 'texi',
  487. 'application/x-texinfo' => 'texinfo',
  488. 'application/x-troff' => 'roff',
  489. 'application/x-troff' => 't',
  490. 'application/x-troff' => 'tr',
  491. 'application/x-troff-man' => 'man',
  492. 'application/x-troff-me' => 'me',
  493. 'application/x-troff-ms' => 'ms',
  494. 'application/x-ustar' => 'ustar',
  495. 'application/x-wais-source' => 'src',
  496. 'application/x-x509-ca-cert' => 'cer',
  497. 'application/ynd.ms-pkipko' => 'pko',
  498. 'application/zip' => 'zip',
  499. 'audio/basic' => 'au',
  500. 'audio/basic' => 'snd',
  501. 'audio/mid' => 'mid',
  502. 'audio/mid' => 'rmi',
  503. 'audio/mpeg' => 'mp3',
  504. 'audio/mp3' => 'mp3',
  505. 'audio/x-aiff' => 'aif',
  506. 'audio/x-aiff' => 'aifc',
  507. 'audio/x-aiff' => 'aiff',
  508. 'audio/x-mpegurl' => 'm3u',
  509. 'audio/x-pn-realaudio' => 'ram',
  510. 'audio/x-wav' => 'wav',
  511. 'image/bmp' => 'bmp',
  512. 'image/cis-cod' => 'cod',
  513. 'image/gif' => 'gif',
  514. 'image/ief' => 'ief',
  515. 'image/jpeg' => 'jpg',
  516. 'image/pipeg' => 'jfif',
  517. 'image/svg+xml' => 'svg',
  518. 'image/tiff' => 'tif',
  519. 'image/tiff' => 'tiff',
  520. 'image/x-cmu-raster' => 'ras',
  521. 'image/x-cmx' => 'cmx',
  522. 'image/x-icon' => 'ico',
  523. 'image/x-portable-anymap' => 'pnm',
  524. 'image/x-portable-bitmap' => 'pbm',
  525. 'image/x-portable-graymap' => 'pgm',
  526. 'image/x-portable-pixmap' => 'ppm',
  527. 'image/x-rgb' => 'rgb',
  528. 'image/x-xbitmap' => 'xbm',
  529. 'image/x-xpixmap' => 'xpm',
  530. 'image/x-xwindowdump' => 'xwd',
  531. 'message/rfc822' => 'mht',
  532. 'message/rfc822' => 'mhtml',
  533. 'message/rfc822' => 'nws',
  534. 'text/css' => 'css',
  535. 'text/h323' => '323',
  536. 'text/html' => 'html',
  537. 'text/iuls' => 'uls',
  538. 'text/plain' => 'txt',
  539. 'text/richtext' => 'rtx',
  540. 'text/scriptlet' => 'sct',
  541. 'text/tab-separated-values' => 'tsv',
  542. 'text/webviewhtml' => 'htt',
  543. 'text/x-component' => 'htc',
  544. 'text/x-setext' => 'etx',
  545. 'text/x-vcard' => 'vcf',
  546. 'video/mpeg' => 'mpeg',
  547. 'video/quicktime' => 'mov',
  548. 'video/x-ms-asf' => 'asx',
  549. 'video/x-msvideo' => 'avi',
  550. 'video/x-sgi-movie' => 'movie',
  551. 'x-world/x-vrml' => 'flr',
  552. 'application/x-rar' => 'rar',
  553. 'application/vnd.android.package-archive' => 'apk',
  554. 'audio/webm' => 'webm',
  555. 'video/webm' => 'webm',
  556. );
  557. if (isset($config[$mine])) {
  558. return $config[$mine];
  559. } else {
  560. return false;
  561. }
  562. }
  563. /**
  564. * getExt
  565. *
  566. * @return mixed
  567. */
  568. protected function getExtByByte($filename)
  569. {
  570. $file = fopen($filename,"rb");
  571. $bin = fread($file,2);
  572. fclose($file);
  573. $strInfo = @unpack("c2chars",$bin);
  574. $typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
  575. $fileType = '';
  576. switch ($typeCode) {
  577. case 7790:
  578. $fileType = 'exe';
  579. break;
  580. case 7784:
  581. $fileType = 'midi';
  582. break;
  583. case 8297:
  584. $fileType = 'rar';
  585. break;
  586. case 255216:
  587. $fileType = 'jpg';
  588. break;
  589. case 7173:
  590. $fileType = 'gif';
  591. break;
  592. case 13780:
  593. $fileType = 'png';
  594. break;
  595. case 6677:
  596. $fileType = 'bmp';
  597. break;
  598. case 6787:
  599. $fileType = 'swf';
  600. break;
  601. case 6063;
  602. $fileType = 'php|xml';
  603. break;
  604. case 6033:
  605. $fileType = 'html|htm|shtml';
  606. break;
  607. case 8075:
  608. $fileType = 'zip';
  609. break;
  610. case 6782:
  611. case 1310:
  612. $fileType = 'txt';
  613. break;
  614. case 4742:
  615. $fileType = 'js';
  616. break;
  617. case 8273:
  618. $fileType = 'wav';
  619. break;
  620. case 7368:
  621. $fileType = 'mp3';
  622. break;
  623. case 3780:
  624. $fileType = 'pdf';
  625. break;
  626. case 4545:
  627. $fileType = 'pem';
  628. break;
  629. case 7597:
  630. $fileType = 'fbx';
  631. break;
  632. default:
  633. $fileType = 'unknown'.$typeCode;
  634. break;
  635. }
  636. if ($strInfo['chars1'] == '-1' && $strInfo['chars2'] == '-40') {
  637. return 'jpg';
  638. }
  639. if ($strInfo['chars1'] == '-119' && $strInfo['chars2'] == '80') {
  640. return 'png';
  641. }
  642. if ($strInfo['chars1'] == '-48' && $strInfo['chars2'] == '-49') {
  643. return 'msi';
  644. }
  645. return $fileType;
  646. }
  647. }