PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/function/web.function.php

https://gitlab.com/imxieke/XCloud
PHP | 576 lines | 503 code | 24 blank | 49 comment | 94 complexity | 3235604999f8933e7515e68b56e3aaae MD5 | raw file
  1. <?php
  2. /*
  3. * @link http://www.kalcaddle.com/
  4. * @author warlee | e-mail:kalcaddle@qq.com
  5. * @copyright warlee 2014.(Shanghai)Co.,Ltd
  6. * @license http://kalcaddle.com/tools/licenses/license.txt
  7. */
  8. /**
  9. * 获取客户端IP地址
  10. *
  11. * @param boolean $s_type ip类型[ip|long]
  12. * @return string $ip
  13. */
  14. function get_client_ip($b_ip = true){
  15. $arr_ip_header = array(
  16. "HTTP_CLIENT_IP",
  17. "HTTP_X_FORWARDED_FOR",
  18. "REMOTE_ADDR",
  19. "HTTP_CDN_SRC_IP",
  20. "HTTP_PROXY_CLIENT_IP",
  21. "HTTP_WL_PROXY_CLIENT_IP"
  22. );
  23. $client_ip = 'unknown';
  24. foreach ($arr_ip_header as $key) {
  25. if (!empty($_SERVER[$key]) && strtolower($_SERVER[$key]) != "unknown") {
  26. $client_ip = $_SERVER[$key];
  27. break;
  28. }
  29. }
  30. if ($pos = strpos($client_ip,',')){
  31. $client_ip = substr($client_ip,$pos+1);
  32. }
  33. return $client_ip;
  34. }
  35. // url头部数据
  36. function url_header($url){
  37. $name = '';$length=0;
  38. $header = @get_headers($url,true);
  39. if (!$header) return false;
  40. if(isset($header['Content-Length'])){
  41. if(is_array($header['Content-Length'])){
  42. $length = array_pop($header['Content-Length']);
  43. }else{
  44. $length = $header['Content-Length'];
  45. }
  46. }
  47. if(isset($header['Content-Disposition'])){
  48. if(is_array($header['Content-Disposition'])){
  49. $dis = array_pop($header['Content-Disposition']);
  50. }else{
  51. $dis = $header['Content-Disposition'];
  52. }
  53. $i = strpos($dis,"filename=");
  54. if($i!= false){
  55. $name = substr($dis,$i+9);
  56. $name = trim($name,'"');
  57. }
  58. }
  59. if(!$name){
  60. $name = get_path_this($url);
  61. if (stripos($name,'?')) $name = substr($name,0,stripos($name,'?'));
  62. if (!$name) $name = 'index.html';
  63. }
  64. // $header['name'] = $name;
  65. // return $header;
  66. return array('length'=>$length,'name'=>$name);
  67. }
  68. // url检查
  69. function check_url($url){
  70. $array = get_headers($url,true);
  71. if (preg_match('/404/', $array[0])) {
  72. return false;
  73. } elseif (preg_match('/403/', $array[0])) {
  74. return false;
  75. } else {
  76. return true;
  77. }
  78. }
  79. /**
  80. * 获取网络url文件内容,加入ua,以解决防采集的站
  81. */
  82. function curl_get_contents($url){
  83. $ch = curl_init();
  84. $timeout = 4;
  85. $user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1)";
  86. curl_setopt ($ch, CURLOPT_URL, $url);
  87. curl_setopt ($ch, CURLOPT_HEADER, 0);
  88. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  89. curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
  90. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  91. $file_contents = curl_exec($ch);
  92. curl_close($ch);
  93. return $file_contents;
  94. }
  95. // 返回refer URL 地址
  96. function refer_url(){
  97. return isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : '';
  98. }
  99. // 返回当前页面的 URL 地址
  100. function this_url(){
  101. $s_url = isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] ? 'https' : 'http';
  102. $s_url .= '://';
  103. return $s_url . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
  104. }
  105. function select_var($array){
  106. if (!is_array($array)) return -1;
  107. ksort($array);
  108. $chosen = -1;
  109. foreach ($array as $k => $v) {
  110. if (isset($v)) {
  111. $chosen = $v;
  112. break;
  113. }
  114. }
  115. return $chosen;
  116. }
  117. function stripslashes_deep($value){
  118. $value = is_array($value) ? array_map('stripslashes_deep', $value) : (isset($value) ? stripslashes($value) : null);
  119. return $value;
  120. }
  121. /**
  122. * GET/POST数据统一入口
  123. * 将GET和POST的数据进行过滤,去掉非法字符以及hacker code,返回一个数组
  124. * 注意如果GET和POST有相同的Key,POST优先
  125. *
  126. * @return array $_GET和$_POST数据过滤处理后的值
  127. */
  128. function parse_incoming(){
  129. global $_GET, $_POST,$_COOKIE;
  130. $_COOKIE = stripslashes_deep($_COOKIE);
  131. $_GET = stripslashes_deep($_GET);
  132. $_POST = stripslashes_deep($_POST);
  133. $return = array();
  134. $return = array_merge($_GET,$_POST);
  135. $remote = array_get($return,0);
  136. $remote = explode('/',trim($remote[0],'/'));
  137. $return['URLremote'] = $remote;
  138. return $return;
  139. }
  140. function url2absolute($index_url, $preg_url){
  141. if (preg_match('/[a-zA-Z]*\:\/\//', $preg_url)) return $preg_url;
  142. preg_match('/([a-zA-Z]*\:\/\/.*)\//', $index_url, $match);
  143. $index_url_temp = $match[1];
  144. foreach(explode('/', $preg_url) as $key => $var) {
  145. if ($key == 0 && $var == '') {
  146. preg_match('/([a-zA-Z]*\:\/\/[^\/]*)\//', $index_url, $match);
  147. $index_url_temp = $match[1] . $preg_url;
  148. break;
  149. }
  150. if ($var == '..') {
  151. preg_match('/([a-zA-Z]*\:\/\/.*)\//', $index_url_temp, $match);
  152. $index_url_temp = $match[1];
  153. } elseif ($var != '.') $index_url_temp .= '/' . $var;
  154. }
  155. return $index_url_temp;
  156. }
  157. // 将字符串转换成URL的编码,gbk的和utf8的 $to="gbk" 或"utf8"
  158. function urlcode($str, $to){
  159. if ($to == "gbk") {
  160. $result = RawUrlEncode($str); //gbk字符(主要是中文)转换为url %BA%EC形式
  161. } else {
  162. $key = mb_convert_encoding($str, "utf-8", "gbk"); //对于百度utf8中文url
  163. $result = urlencode($key);
  164. }
  165. return $result;
  166. }
  167. // 输出js
  168. function exec_js($js){
  169. echo "<script language='JavaScript'>\n" . $js . "</script>\n";
  170. }
  171. // 禁止缓存
  172. function no_cache(){
  173. header("Pragma:no-cache\r\n");
  174. header("Cache-Control:no-cache\r\n");
  175. header("Expires:0\r\n");
  176. }
  177. // 生成javascript转向
  178. function go_url($url, $msg = ''){
  179. header("Content-type: text/html; charset=utf-8\r\n");
  180. echo "<script type='text/javascript'>\n";
  181. echo "window.location.href='$direction';";
  182. echo "</script>\n";
  183. exit;
  184. }
  185. /**
  186. * 消息框。eg
  187. * msg("falied","/",10);
  188. * msg("ok");
  189. */
  190. function show_msg($message, $url = '#', $time = 3, $isgo = 1)
  191. {
  192. $goto = "content='$time;url=$url'";
  193. if ($isgo != "1") {
  194. $goto = "";
  195. } //是否自动跳转
  196. echo<<<END
  197. <html>
  198. <meta http-equiv='refresh' $goto charset="utf-8">
  199. <style>
  200. #msgbox{width:400px;border: 1px solid #ddd;font-family:微软雅黑;color:888;font-size:13px;margin:0 auto;margin-top:150px;}
  201. #msgbox #title{background:#3F9AC6;color:#fff;line-height:30px;height:30px;padding-left:20px;font-weight:800;}
  202. #msgbox #message{text-align:center;padding:20px;}
  203. #msgbox #info{text-align:center;padding:5px;border-top:1px solid #ddd;background:#f2f2f2;color:#888;}
  204. </style>
  205. <body>
  206. <div id="msgbox">
  207. <div id="title">提示信息</div>
  208. <div id="message">$message</div>
  209. <div id="info">$time 秒后自动跳转如不想等待可 <a href='$url'>点击这里</a></div></center>
  210. </body>
  211. </html>
  212. END;
  213. exit;
  214. }
  215. function send_http_status($i_status, $s_message = ''){
  216. $a_status = array(
  217. // Informational 1xx
  218. 100 => 'Continue',
  219. 101 => 'Switching Protocols',
  220. // Success 2xx
  221. 200 => 'OK',
  222. 201 => 'Created',
  223. 202 => 'Accepted',
  224. 203 => 'Non-Authoritative Information',
  225. 204 => 'No Content',
  226. 205 => 'Reset Content',
  227. 206 => 'Partial Content',
  228. // Redirection 3xx
  229. 300 => 'Multiple Choices',
  230. 301 => 'Moved Permanently',
  231. 302 => 'Found', // 1.1
  232. 303 => 'See Other',
  233. 304 => 'Not Modified',
  234. 305 => 'Use Proxy', // 306 is deprecated but reserved
  235. 307 => 'Temporary Redirect',
  236. // Client Error 4xx
  237. 400 => 'Bad Request',
  238. 401 => 'Unauthorized',
  239. 402 => 'Payment Required',
  240. 403 => 'Forbidden',
  241. 404 => 'Not Found',
  242. 405 => 'Method Not Allowed',
  243. 406 => 'Not Acceptable',
  244. 407 => 'Proxy Authentication Required',
  245. 408 => 'Request Timeout',
  246. 409 => 'Conflict',
  247. 410 => 'Gone',
  248. 411 => 'Length Required',
  249. 412 => 'Precondition Failed',
  250. 413 => 'Request Entity Too Large',
  251. 414 => 'Request-URI Too Long',
  252. 415 => 'Unsupported Media Type',
  253. 416 => 'Requested Range Not Satisfiable',
  254. 417 => 'Expectation Failed',
  255. // Server Error 5xx
  256. 500 => 'Internal Server Error',
  257. 501 => 'Not Implemented',
  258. 502 => 'Bad Gateway',
  259. 503 => 'Service Unavailable',
  260. 504 => 'Gateway Timeout',
  261. 505 => 'HTTP Version Not Supported',
  262. 509 => 'Bandwidth Limit Exceeded'
  263. );
  264. if (array_key_exists($i_status, $a_status)) {
  265. header('HTTP/1.1 ' . $i_status . ' ' . $a_status[$i_status]);
  266. }
  267. if ($s_message) {
  268. echo $s_message;
  269. exit();
  270. }
  271. }
  272. // 获取操作系统信息
  273. function get_os (){
  274. $agent = $_SERVER['HTTP_USER_AGENT'];
  275. $os = false;
  276. if (eregi('win', $agent) && strpos($agent, '95')) {
  277. $os = 'Windows 95';
  278. } else if (eregi('win 9x', $agent) && strpos($agent, '4.90')) {
  279. $os = 'Windows ME';
  280. } else if (eregi('win', $agent) && ereg('98', $agent)) {
  281. $os = 'Windows 98';
  282. } else if (eregi('win', $agent) && eregi('nt 5.1', $agent)) {
  283. $os = 'Windows XP';
  284. } else if (eregi('win', $agent) && eregi('nt 5', $agent)) {
  285. $os = 'Windows 2000';
  286. } else if (eregi('win', $agent) && eregi('nt', $agent)) {
  287. $os = 'Windows NT';
  288. } else if (eregi('win', $agent) && ereg('32', $agent)) {
  289. $os = 'Windows 32';
  290. } else if (eregi('linux', $agent)) {
  291. $os = 'Linux';
  292. } else if (eregi('unix', $agent)) {
  293. $os = 'Unix';
  294. } else if (eregi('sun', $agent) && eregi('os', $agent)) {
  295. $os = 'SunOS';
  296. } else if (eregi('ibm', $agent) && eregi('os', $agent)) {
  297. $os = 'IBM OS/2';
  298. } else if (eregi('Mac', $agent) && eregi('PC', $agent)) {
  299. $os = 'Macintosh';
  300. } else if (eregi('PowerPC', $agent)) {
  301. $os = 'PowerPC';
  302. } else if (eregi('AIX', $agent)) {
  303. $os = 'AIX';
  304. } else if (eregi('HPUX', $agent)) {
  305. $os = 'HPUX';
  306. } else if (eregi('NetBSD', $agent)) {
  307. $os = 'NetBSD';
  308. } else if (eregi('BSD', $agent)) {
  309. $os = 'BSD';
  310. } else if (ereg('OSF1', $agent)) {
  311. $os = 'OSF1';
  312. } else if (ereg('IRIX', $agent)) {
  313. $os = 'IRIX';
  314. } else if (eregi('FreeBSD', $agent)) {
  315. $os = 'FreeBSD';
  316. } else if (eregi('teleport', $agent)) {
  317. $os = 'teleport';
  318. } else if (eregi('flashget', $agent)) {
  319. $os = 'flashget';
  320. } else if (eregi('webzip', $agent)) {
  321. $os = 'webzip';
  322. } else if (eregi('offline', $agent)) {
  323. $os = 'offline';
  324. } else {
  325. $os = 'Unknown';
  326. }
  327. return $os;
  328. }
  329. //根据扩展名获取mime
  330. function get_file_mime($ext){
  331. $mimetypes = array(
  332. "323" => "text/h323",
  333. "acx" => "application/internet-property-stream",
  334. "ai" => "application/postscript",
  335. "aif" => "audio/x-aiff",
  336. "aifc" => "audio/x-aiff",
  337. "aiff" => "audio/x-aiff",
  338. "asf" => "video/x-ms-asf",
  339. "asr" => "video/x-ms-asf",
  340. "asx" => "video/x-ms-asf",
  341. "au" => "audio/basic",
  342. "avi" => "video/x-msvideo",
  343. "axs" => "application/olescript",
  344. "bas" => "text/plain",
  345. "bcpio" => "application/x-bcpio",
  346. "bin" => "application/octet-stream",
  347. "bmp" => "image/bmp",
  348. "c" => "text/plain",
  349. "cat" => "application/vnd.ms-pkiseccat",
  350. "cdf" => "application/x-cdf",
  351. "cer" => "application/x-x509-ca-cert",
  352. "class" => "application/octet-stream",
  353. "clp" => "application/x-msclip",
  354. "cmx" => "image/x-cmx",
  355. "cod" => "image/cis-cod",
  356. "cpio" => "application/x-cpio",
  357. "crd" => "application/x-mscardfile",
  358. "crl" => "application/pkix-crl",
  359. "crt" => "application/x-x509-ca-cert",
  360. "csh" => "application/x-csh",
  361. "css" => "text/css",
  362. "dcr" => "application/x-director",
  363. "der" => "application/x-x509-ca-cert",
  364. "dir" => "application/x-director",
  365. "dll" => "application/x-msdownload",
  366. "dms" => "application/octet-stream",
  367. "doc" => "application/msword",
  368. "docx" => "application/msword",
  369. "dot" => "application/msword",
  370. "dvi" => "application/x-dvi",
  371. "dxr" => "application/x-director",
  372. "eps" => "application/postscript",
  373. "etx" => "text/x-setext",
  374. "evy" => "application/envoy",
  375. "exe" => "application/octet-stream",
  376. "fif" => "application/fractals",
  377. "flr" => "x-world/x-vrml",
  378. "gif" => "image/gif",
  379. "gtar" => "application/x-gtar",
  380. "gz" => "application/x-gzip",
  381. "h" => "text/plain",
  382. "hdf" => "application/x-hdf",
  383. "hlp" => "application/winhlp",
  384. "hqx" => "application/mac-binhex40",
  385. "hta" => "application/hta",
  386. "htc" => "text/x-component",
  387. "htm" => "text/html",
  388. "html" => "text/html",
  389. "htt" => "text/webviewhtml",
  390. "ico" => "image/x-icon",
  391. "ief" => "image/ief",
  392. "iii" => "application/x-iphone",
  393. "ins" => "application/x-internet-signup",
  394. "isp" => "application/x-internet-signup",
  395. "jfif" => "image/pipeg",
  396. "jpe" => "image/jpeg",
  397. "jpeg" => "image/jpeg",
  398. "jpg" => "image/jpeg",
  399. "js" => "application/x-javascript",
  400. "latex" => "application/x-latex",
  401. "lha" => "application/octet-stream",
  402. "lsf" => "video/x-la-asf",
  403. "lsx" => "video/x-la-asf",
  404. "lzh" => "application/octet-stream",
  405. "m13" => "application/x-msmediaview",
  406. "m14" => "application/x-msmediaview",
  407. "m3u" => "audio/x-mpegurl",
  408. "man" => "application/x-troff-man",
  409. "mdb" => "application/x-msaccess",
  410. "me" => "application/x-troff-me",
  411. "mht" => "message/rfc822",
  412. "mhtml" => "message/rfc822",
  413. "mid" => "audio/mid",
  414. "mny" => "application/x-msmoney",
  415. "mov" => "video/quicktime",
  416. "movie" => "video/x-sgi-movie",
  417. "mp2" => "video/mpeg",
  418. "mp3" => "audio/mpeg",
  419. "mp4" => "video/mpeg",
  420. "mpa" => "video/mpeg",
  421. "mpe" => "video/mpeg",
  422. "mpeg" => "video/mpeg",
  423. "mpg" => "video/mpeg",
  424. "mpp" => "application/vnd.ms-project",
  425. "mpv2" => "video/mpeg",
  426. "ms" => "application/x-troff-ms",
  427. "mvb" => "application/x-msmediaview",
  428. "nws" => "message/rfc822",
  429. "oda" => "application/oda",
  430. "p10" => "application/pkcs10",
  431. "p12" => "application/x-pkcs12",
  432. "p7b" => "application/x-pkcs7-certificates",
  433. "p7c" => "application/x-pkcs7-mime",
  434. "p7m" => "application/x-pkcs7-mime",
  435. "p7r" => "application/x-pkcs7-certreqresp",
  436. "p7s" => "application/x-pkcs7-signature",
  437. "pbm" => "image/x-portable-bitmap",
  438. "pdf" => "application/pdf",
  439. "pfx" => "application/x-pkcs12",
  440. "pgm" => "image/x-portable-graymap",
  441. "pko" => "application/ynd.ms-pkipko",
  442. "pma" => "application/x-perfmon",
  443. "pmc" => "application/x-perfmon",
  444. "pml" => "application/x-perfmon",
  445. "pmr" => "application/x-perfmon",
  446. "pmw" => "application/x-perfmon",
  447. "png" => "image/png",
  448. "pnm" => "image/x-portable-anymap",
  449. "pot," => "application/vnd.ms-powerpoint",
  450. "ppm" => "image/x-portable-pixmap",
  451. "pps" => "application/vnd.ms-powerpoint",
  452. "ppt" => "application/vnd.ms-powerpoint",
  453. "pptx" => "application/vnd.ms-powerpoint",
  454. "prf" => "application/pics-rules",
  455. "ps" => "application/postscript",
  456. "pub" => "application/x-mspublisher",
  457. "qt" => "video/quicktime",
  458. "ra" => "audio/x-pn-realaudio",
  459. "ram" => "audio/x-pn-realaudio",
  460. "ras" => "image/x-cmu-raster",
  461. "rgb" => "image/x-rgb",
  462. "rmi audio/mid" => "http://www.dreamdu.com",
  463. "roff" => "application/x-troff",
  464. "rtf" => "application/rtf",
  465. "rtx" => "text/richtext",
  466. "scd" => "application/x-msschedule",
  467. "sct" => "text/scriptlet",
  468. "setpay" => "application/set-payment-initiation",
  469. "setreg" => "application/set-registration-initiation",
  470. "sh" => "application/x-sh",
  471. "shar" => "application/x-shar",
  472. "sit" => "application/x-stuffit",
  473. "snd" => "audio/basic",
  474. "spc" => "application/x-pkcs7-certificates",
  475. "spl" => "application/futuresplash",
  476. "src" => "application/x-wais-source",
  477. "sst" => "application/vnd.ms-pkicertstore",
  478. "stl" => "application/vnd.ms-pkistl",
  479. "stm" => "text/html",
  480. "svg" => "image/svg+xml",
  481. "sv4cpio" => "application/x-sv4cpio",
  482. "sv4crc" => "application/x-sv4crc",
  483. "swf" => "application/x-shockwave-flash",
  484. "t" => "application/x-troff",
  485. "tar" => "application/x-tar",
  486. "tcl" => "application/x-tcl",
  487. "tex" => "application/x-tex",
  488. "texi" => "application/x-texinfo",
  489. "texinfo" => "application/x-texinfo",
  490. "tgz" => "application/x-compressed",
  491. "tif" => "image/tiff",
  492. "tiff" => "image/tiff",
  493. "tr" => "application/x-troff",
  494. "trm" => "application/x-msterminal",
  495. "tsv" => "text/tab-separated-values",
  496. "txt" => "text/plain",
  497. "uls" => "text/iuls",
  498. "ustar" => "application/x-ustar",
  499. "vcf" => "text/x-vcard",
  500. "vrml" => "x-world/x-vrml",
  501. "wav" => "audio/x-wav",
  502. "wcm" => "application/vnd.ms-works",
  503. "wdb" => "application/vnd.ms-works",
  504. "wks" => "application/vnd.ms-works",
  505. "wmf" => "application/x-msmetafile",
  506. "wps" => "application/vnd.ms-works",
  507. "wri" => "application/x-mswrite",
  508. "wrl" => "x-world/x-vrml",
  509. "wrz" => "x-world/x-vrml",
  510. "xaf" => "x-world/x-vrml",
  511. "xbm" => "image/x-xbitmap",
  512. "xla" => "application/vnd.ms-excel",
  513. "xlc" => "application/vnd.ms-excel",
  514. "xlm" => "application/vnd.ms-excel",
  515. "xls" => "application/vnd.ms-excel",
  516. "xlsx" => "application/vnd.ms-excel",
  517. "xlt" => "application/vnd.ms-excel",
  518. "xlw" => "application/vnd.ms-excel",
  519. "xof" => "x-world/x-vrml",
  520. "xpm" => "image/x-xpixmap",
  521. "xwd" => "image/x-xwindowdump",
  522. "z" => "application/x-compress",
  523. "zip" => "application/zip"
  524. );
  525. //代码 或文本浏览器输出
  526. $text = array('oexe','inc','inf','csv','log','asc','tsv');
  527. $code = array("abap","abc","as","ada","adb","htgroups","htpasswd","conf","htaccess","htgroups",
  528. "htpasswd","asciidoc","asm","ahk","bat","cmd","c9search_results","cpp","c","cc","cxx","h","hh","hpp",
  529. "cirru","cr","clj","cljs","CBL","COB","coffee","cf","cson","Cakefile","cfm","cs","css","curly","d",
  530. "di","dart","diff","patch","Dockerfile","dot","dummy","dummy","e","ejs","ex","exs","elm","erl",
  531. "hrl","frt","fs","ldr","ftl","gcode","feature",".gitignore","glsl","frag","vert","go","groovy",
  532. "haml","hbs","handlebars","tpl","mustache","hs","hx","html","htm","xhtml","erb","rhtml","ini",
  533. "cfg","prefs","io","jack","jade","java","js","jsm","json","jq","jsp","jsx","jl","tex","latex",
  534. "ltx","bib","lean","hlean","less","liquid","lisp","ls","logic","lql","lsl","lua","lp","lucene",
  535. "Makefile","GNUmakefile","makefile","OCamlMakefile","make","md","markdown","mask","matlab",
  536. "mel","mc","mush","mysql","nix","m","mm","ml","mli","pas","p","pl","pm","pgsql","php","phtml",
  537. "ps1","praat","praatscript","psc","proc","plg","prolog","properties","proto","py","r","Rd",
  538. "Rhtml","rb","ru","gemspec","rake","Guardfile","Rakefile","Gemfile","rs","sass","scad","scala",
  539. "scm","rkt","scss","sh","bash",".bashrc","sjs","smarty","tpl","snippets","soy","space","sql",
  540. "styl","stylus","svg","tcl","tex","txt","textile","toml","twig","ts","typescript","str","vala",
  541. "vbs","vb","vm","v","vh","sv","svh","vhd","vhdl","xml","rdf","rss",
  542. "wsdl","xslt","atom","mathml","mml","xul","xbl","xaml","xq","yaml","yml","htm",
  543. "xib","storyboard","plist","csproj");
  544. if (array_key_exists($ext,$mimetypes)){
  545. return $mimetypes[$ext];
  546. }else{
  547. if(in_array($ext,$text) || in_array($ext,$code)){
  548. return "text/plain";
  549. }
  550. return 'application/octet-stream';
  551. }
  552. }