Core.php 18 KB

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