You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.8 KiB

  1. <?php
  2. function ___sortcmp()
  3. {
  4. $a = func_get_arg(0);
  5. $b = func_get_arg(1);
  6. return strcasecmp($a, $b);
  7. }
  8. function ___codepre()
  9. {
  10. $str = func_get_arg(0);
  11. if (func_num_args() > 1) {
  12. $arr1 = array("&", "\"", "'", "<", ">", '"');
  13. $arr2 = array("&amp;", "&quot;", "&apos;", "&lt;", "&gt;", "&#039;");
  14. } else {
  15. $arr1 = array("&", "\"", "'", "<", ">", " ", '"');
  16. $arr2 = array("&amp;", "&quot;", "&apos;", "&lt;", "&gt;", "&nbsp;", "&#039;");
  17. }
  18. return str_replace($arr1, $arr2, $str);
  19. }
  20. function ___ziplist()
  21. {
  22. $zip = trim(func_get_arg(0));
  23. if (!is_readable('pclzip.php') || !___getmime($zip, 'zip')) {
  24. return false;
  25. }
  26. require 'pclzip.php';
  27. $pclzip = new pclzip($zip);
  28. if (!($getlist = $pclzip->listContent())) {
  29. return false;
  30. }
  31. if (!is_array($getlist) || count($getlist) < 1) {
  32. return false;
  33. }
  34. return $getlist;
  35. }
  36. function ___convert()
  37. {
  38. $str = func_get_arg(0);
  39. if (!function_exists("mb_convert_encoding")) {
  40. return $str;
  41. }
  42. $encode = func_num_args() < 2 ? "UTF-8" : func_get_arg(1);
  43. $enlist = func_num_args() > 2 ? func_get_arg(2) : "auto,CP936";
  44. return mb_convert_encoding($str, $encode, $enlist);
  45. }
  46. function ___getmime()
  47. {
  48. $path = trim(func_get_arg(0));
  49. if (func_num_args() >= 2) {
  50. $type = trim(func_get_arg(1));
  51. $type = explode(':', $type);
  52. }
  53. if (!is_file($path)) {
  54. return false;
  55. }
  56. if (!($fp = fopen($path, "rb"))) {
  57. return false;
  58. }
  59. $bsupport = array(
  60. array('jpg', 'ffd8ff', 'image/jpeg'),
  61. array('png', '89504e47', 'image/png'),
  62. array('gif', '47494638', 'image/gif'),
  63. array('bmp', '424d', 'image/x-ms-bmp'),
  64. array('zip', '504b0304', 'application/zip'));
  65. $headstr = bin2hex(fread($fp, 4));
  66. fclose($fp);
  67. foreach ($bsupport as $temp) {
  68. if (preg_match("/^$temp[1]/i", $headstr)) {
  69. if (!isset($type)) {
  70. return $temp[2];
  71. } elseif (in_array($temp[0], $type)) {
  72. return $temp[2];
  73. }
  74. }
  75. }
  76. return false;
  77. }
  78. function ___sendfile()
  79. {
  80. $i = 0;
  81. $to = func_get_arg(0);
  82. $fs = func_get_arg(1);
  83. if (!is_file("email.php")) {
  84. return false;
  85. } else {
  86. require "email.php";
  87. }
  88. if ($to == "" || !is_array($fs)) {
  89. return false;
  90. } elseif (count($fs) < 1) {
  91. return false;
  92. }
  93. $systags = uniqid("");
  94. $subject = "your files";
  95. $headers = "Content-Type: multipart/mixed; boundary=\"$systags\"\r\n";
  96. $emailbody = "--$systags\r\n";
  97. $emailbody .= "Content-type: text/plain; charset=utf-8\r\n";
  98. $emailbody .= "Content-transfer-encoding: 8bit\r\n\r\n";
  99. while ($i < count($fs)) {
  100. if (!is_file($fs[$i]) || !is_readable($fs[$i])) {
  101. continue;
  102. }
  103. $attachment = chunk_split(base64_encode(file_get_contents($fs[$i])));
  104. $emailbody .= "--$systags\r\n";
  105. $emailbody .= "Content-type: application/octet-stream; name=" . ___basename($fs[$i]) . "\r\n";
  106. $emailbody .= "Content-transfer-encoding: base64\r\n\r\n";
  107. $emailbody .= "$attachment\r\n\r\n";
  108. $i++;
  109. }
  110. $emailbody .= "--$systags--";
  111. return email($to, "from aite.xyz file manager", $emailbody, $headers);
  112. }
  113. function ___download()
  114. {
  115. $path = trim(func_get_arg(0));
  116. $size = filesize($path);
  117. (isset($_SERVER['HTTP_RANGE']) && !empty($_SERVER['HTTP_RANGE']) && $range = substr($_SERVER['HTTP_RANGE'], 6)) || $range = '0-' . ($size - 1);
  118. if (substr($range, -1) == '-') {
  119. $init = substr($range, 0, -1);
  120. $stop = $size - 1;
  121. } elseif (substr($range, 0, 1) == '-') {
  122. $init = $size - substr($range, 1) - 1;
  123. $stop = $size - 1;
  124. } else {
  125. $init_stop = explode('-', $range);
  126. $init = $init_stop[0];
  127. $stop = $init_stop[1];
  128. }
  129. if (isset($_SERVER['HTTP_RANGE'])) {
  130. header('HTTP/1.1 206 Partial Content');
  131. }
  132. header('Accept-Ranges: bytes');
  133. header('Content-Type: application/force-download');
  134. header('Content-Disposition: attachment; filename=' . ___basename($path));
  135. header("Content-Range: bytes $init-$stop/$size");
  136. header('Content-Length: ' . ($stop - $init + 1));
  137. $fp = fopen($path, "rb");
  138. fseek($fp, $init);
  139. while (!feof($fp)) {
  140. echo fread($fp, 4096);
  141. if (ftell($fp) > $stop) {
  142. break;
  143. }
  144. }
  145. fclose($fp);
  146. }
  147. function ___basename()
  148. {
  149. $path = trim(func_get_arg(0));
  150. $path = str_replace("\\", "/", $path);
  151. $path = explode("/", $path);
  152. return ___convert($path[count($path) - 1]);
  153. }
  154. function ___realpath()
  155. {
  156. $path = func_get_arg(0);
  157. $path = str_replace('\\', '/', $path);
  158. if (!is_link($path)) {
  159. return realpath($path);
  160. }
  161. return preg_replace('/[^:]?\/{2,}/si', '/', $path);
  162. }
  163. function ___filesize()
  164. {
  165. $size = trim(func_get_arg(0));
  166. if ($size < 1024) {
  167. return $size . " B";
  168. } elseif ($size < 1024 * 1024) {
  169. return number_format($size / 1024, 3) . " KB";
  170. } elseif ($size < 1024 * 1024 * 1024) {
  171. return number_format($size / 1024 / 1024, 3) . " MB";
  172. } elseif ($size < 1024 * 1024 * 1024 * 1024) {
  173. return number_format($size / 1024 / 1024 / 1024, 3) . " GB";
  174. } else {
  175. return number_format($size / 1024 / 1024 / 1024 / 1024, 3) . " TB";
  176. }
  177. }
  178. function ___superexec()
  179. {
  180. $cmd = trim(func_get_arg(0));
  181. if (php_uname("s") != "Linux") {
  182. return false;
  183. }
  184. if ($cmd == "" || !function_exists("proc_open") || !function_exists("stream_get_contents")) {
  185. return false;
  186. }
  187. if (!is_resource($sh = proc_open("exec sh", array(0 => array("pipe", "r"), 1 => array("pipe", "w")), $pipes))) {
  188. return false;
  189. }
  190. fwrite($pipes[0], "export LANG=\"zh_CN.utf8\"\n");
  191. fwrite($pipes[0], $cmd);
  192. fclose($pipes[0]);
  193. $result = stream_get_contents($pipes[1]);
  194. fclose($pipes[1]);
  195. proc_close($sh);
  196. return trim($result);
  197. }
  198. function ___shortpath()
  199. {
  200. $path = trim(func_get_arg(0));
  201. $path = ___convert($path, "UTF-8");
  202. if (function_exists('mb_strlen')) {
  203. if (mb_strlen($path, "UTF-8") <= 18) {
  204. return $path;
  205. }
  206. } else {
  207. if (strlen($path) <= 18) {
  208. return $path;
  209. }
  210. }
  211. $path1 = function_exists('mb_substr') ? mb_substr($path, -9, 9, "UTF-8") : substr($path, -9);
  212. $path2 = function_exists('mb_substr') ? mb_substr($path, 0, 9, "UTF-8") : substr($path, 0, 9);
  213. return $path2 . "&ensp;....&ensp;" . $path1;
  214. }
  215. function ___windowsdisk()
  216. {
  217. $disks = array();
  218. foreach (range('A', 'Z') as $item) {
  219. $item = sprintf("%s:\\", $item);
  220. if (is_dir($item)) {
  221. $disks[] = $item;
  222. }
  223. }
  224. if (empty($disks)) {
  225. return false;
  226. }
  227. return $disks;
  228. }
  229. ?>