index.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <?php
  2. include 'auto.php';
  3. if (IS_SAE)
  4. header("Location: index_sae.php");
  5. define('APP_DIR', _dir_path(substr(dirname(__FILE__), 0, -15)));//项目目录
  6. define('SITE_DIR', _dir_path(substr(dirname(__FILE__), 0, -8)));//入口文件目录
  7. if (file_exists('./install.lock')) {
  8. echo '
  9. <html>
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  12. </head>
  13. <body>
  14. 你已经安装过该系统,如果想重新安装,请先删除install目录下的 install.lock 文件,然后再安装。
  15. </body>
  16. </html>';
  17. exit;
  18. }
  19. @set_time_limit(1000);
  20. if (PHP_EDITION > phpversion()) {
  21. header("Content-type:text/html;charset=utf-8");
  22. exit('您的php版本过低,不能安装本软件,请升级到' . PHP_EDITION . '或更高版本再安装,谢谢!');
  23. }
  24. if (phpversion() > '7.4') {
  25. header("Content-type:text/html;charset=utf-8");
  26. exit('您的php版本太高,不能安装本软件,兼容php版本7.1~7.3,谢谢!');
  27. }
  28. define("CRMEB_VERSION", '20180601');
  29. date_default_timezone_set('PRC');
  30. error_reporting(E_ALL & ~E_NOTICE);
  31. header('Content-Type: text/html; charset=UTF-8');
  32. //define('SITEDIR2', substr(SITEDIR,0,-7));
  33. //echo SITEDIR;
  34. //exit;SITE_DIR
  35. //数据库
  36. $sqlFile = 'crmeb.sql';
  37. $configFile = '.env';
  38. if (!file_exists(SITE_DIR . 'install/' . $sqlFile) || !file_exists(SITE_DIR . 'install/' . $configFile)) {
  39. echo '缺少必要的安装文件!';
  40. exit;
  41. }
  42. $Title = "CRMEB安装向导";
  43. $Powered = "Powered by CRMEB";
  44. $steps = array(
  45. '1' => '安装许可协议',
  46. '2' => '运行环境检测',
  47. '3' => '安装参数设置',
  48. '4' => '安装详细过程',
  49. '5' => '安装完成',
  50. );
  51. $step = isset($_GET['step']) ? $_GET['step'] : 1;
  52. //地址
  53. $scriptName = !empty($_SERVER["REQUEST_URI"]) ? $scriptName = $_SERVER["REQUEST_URI"] : $scriptName = $_SERVER["PHP_SELF"];
  54. $rootpath = @preg_replace("/\/(I|i)nstall\/index\.php(.*)$/", "", $scriptName);
  55. $domain = empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
  56. if ((int)$_SERVER['SERVER_PORT'] != 80) {
  57. $domain .= ":" . $_SERVER['SERVER_PORT'];
  58. }
  59. $domain = $domain . $rootpath;
  60. switch ($step) {
  61. case '1':
  62. include_once("./templates/step1.php");
  63. exit();
  64. case '2':
  65. if (phpversion() <= PHP_EDITION) {
  66. die('本系统需要PHP版本 >= ' . PHP_EDITION . '环境,当前PHP版本为:' . phpversion());
  67. }
  68. $phpv = @ phpversion();
  69. $os = PHP_OS;
  70. //$os = php_uname();
  71. $tmp = function_exists('gd_info') ? gd_info() : array();
  72. $server = $_SERVER["SERVER_SOFTWARE"];
  73. $host = (empty($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_HOST"] : $_SERVER["SERVER_ADDR"]);
  74. $name = $_SERVER["SERVER_NAME"];
  75. $max_execution_time = ini_get('max_execution_time');
  76. $allow_reference = (ini_get('allow_call_time_pass_reference') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
  77. $allow_url_fopen = (ini_get('allow_url_fopen') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
  78. $safe_mode = (ini_get('safe_mode') ? '<font color=red>[×]On</font>' : '<font color=green>[√]Off</font>');
  79. $err = 0;
  80. if (empty($tmp['GD Version'])) {
  81. $gd = '<font color=red>[×]Off</font>';
  82. $err++;
  83. } else {
  84. $gd = '<font color=green>[√]On</font> ' . $tmp['GD Version'];
  85. }
  86. if (extension_loaded('redis')) {
  87. $redis = '<span class="correct_span">&radic;</span> 已安装';
  88. } else {
  89. $redis = '<a href="http://help.crmeb.net/crmebpro/1707557" target="_blank"><span class="correct_span error_span">&radic;</span> 点击查看帮助</a>';
  90. $err++;
  91. }
  92. if (function_exists('mysqli_connect')) {
  93. $mysql = '<span class="correct_span">&radic;</span> 已安装';
  94. } else {
  95. $mysql = '<span class="correct_span error_span">&radic;</span> 请安装mysqli扩展';
  96. $err++;
  97. }
  98. if (ini_get('file_uploads')) {
  99. $uploadSize = '<span class="correct_span">&radic;</span> ' . ini_get('upload_max_filesize');
  100. } else {
  101. $uploadSize = '<span class="correct_span error_span">&radic;</span>禁止上传';
  102. }
  103. if (function_exists('session_start')) {
  104. $session = '<span class="correct_span">&radic;</span> 支持';
  105. } else {
  106. $session = '<span class="correct_span error_span">&radic;</span> 不支持';
  107. $err++;
  108. }
  109. if (function_exists('curl_init')) {
  110. $curl = '<font color=green>[√]支持</font> ';
  111. } else {
  112. $curl = '<font color=red>[×]不支持</font>';
  113. $err++;
  114. }
  115. if (function_exists('bcadd')) {
  116. $bcmath = '<font color=green>[√]支持</font> ';
  117. } else {
  118. $bcmath = '<font color=red>[×]不支持</font>';
  119. $err++;
  120. }
  121. if (function_exists('openssl_encrypt')) {
  122. $openssl = '<font color=green>[√]支持</font> ';
  123. } else {
  124. $openssl = '<font color=red>[×]不支持</font>';
  125. $err++;
  126. }
  127. if (function_exists('finfo_open')) {
  128. $finfo_open = '<font color=green>[√]支持</font> ';
  129. } else {
  130. $finfo_open = '<a href="http://help.crmeb.net/crmebpro/1707557" target="_blank"><span class="correct_span error_span">&radic;</span>点击查看帮助</a>';
  131. $err++;
  132. }
  133. $folder = array(
  134. 'public/install',
  135. 'public/uploads',
  136. 'runtime',
  137. );
  138. $file = array(
  139. '.env'
  140. );
  141. //必须开启函数
  142. if (function_exists('file_put_contents')) {
  143. $file_put_contents = '<font color=green>[√]开启</font> ';
  144. } else {
  145. $file_put_contents = '<font color=red>[×]关闭</font>';
  146. $err++;
  147. }
  148. if (function_exists('imagettftext')) {
  149. $imagettftext = '<font color=green>[√]开启</font> ';
  150. } else {
  151. $imagettftext = '<font color=red>[×]关闭</font>';
  152. $err++;
  153. }
  154. include_once("./templates/step2.php");
  155. exit();
  156. case '3':
  157. $dbName = strtolower(trim($_POST['dbName']));
  158. $_POST['dbport'] = $_POST['dbport'] ? $_POST['dbport'] : '3306';
  159. if ($_GET['testdbpwd']) {
  160. $dbHost = $_POST['dbHost'];
  161. $conn = @mysqli_connect($dbHost, $_POST['dbUser'], $_POST['dbPwd'], NULL, $_POST['dbport']);
  162. if (mysqli_connect_errno($conn)) {
  163. die(json_encode(0));
  164. } else {
  165. $result = mysqli_query($conn, "SELECT @@global.sql_mode");
  166. $result = $result->fetch_array();
  167. $version = mysqli_get_server_info($conn);
  168. if ($version >= 5.7) {
  169. if (strstr($result[0], 'STRICT_TRANS_TABLES') || strstr($result[0], 'STRICT_ALL_TABLES') || strstr($result[0], 'TRADITIONAL') || strstr($result[0], 'ANSI'))
  170. exit(json_encode(-1));
  171. }
  172. $result = mysqli_query($conn, "select count(table_name) as c from information_schema.`TABLES` where table_schema='$dbName'");
  173. $result = $result->fetch_array();
  174. if ($result['c'] > 0)
  175. exit(json_encode(-2));
  176. }
  177. //redis数据库信息
  178. $rbhost = $_POST['rbhost'] ?? '127.0.0.1';
  179. $rbport = $_POST['rbport'] ?? 6379;
  180. $rbpw = $_POST['rbpw'] ?? '';
  181. $rbselect = $_POST['rbselect'] ?? 0;
  182. try {
  183. $redis = new \Redis();
  184. $redis->connect($rbhost, $rbport);
  185. if ($rbpw) {
  186. $redis->auth($rbpw);
  187. }
  188. if ($rbselect) {
  189. $redis->select($rbselect);
  190. }
  191. $res = $redis->set('install', 1, 10);
  192. if ($res) {
  193. exit(json_encode(1));
  194. } else {
  195. exit(json_encode(-3));
  196. }
  197. } catch (\Throwable $e) {
  198. exit(json_encode(-3));
  199. }
  200. }
  201. include_once("./templates/step3.php");
  202. exit();
  203. case '4':
  204. if (intval($_GET['install'])) {
  205. $n = intval($_GET['n']);
  206. if ($i == 999999)
  207. exit;
  208. $arr = array();
  209. $dbHost = trim($_POST['dbhost']);
  210. $_POST['dbport'] = $_POST['dbport'] ? $_POST['dbport'] : '3306';
  211. $dbName = strtolower(trim($_POST['dbname']));
  212. $dbUser = trim($_POST['dbuser']);
  213. $dbPwd = trim($_POST['dbpw']);
  214. $dbPrefix = empty($_POST['dbprefix']) ? 'eb_' : trim($_POST['dbprefix']);
  215. $username = trim($_POST['manager']);
  216. $password = trim($_POST['manager_pwd']);
  217. $email = trim($_POST['manager_email']);
  218. if (!function_exists('mysqli_connect')) {
  219. $arr['msg'] = "请安装 mysqli 扩展!";
  220. echo json_encode($arr);
  221. exit;
  222. }
  223. $conn = @mysqli_connect($dbHost, $dbUser, $dbPwd, NULL, $_POST['dbport']);
  224. if (mysqli_connect_errno($conn)) {
  225. $arr['msg'] = "连接数据库失败!" . mysqli_connect_error($conn);
  226. echo json_encode($arr);
  227. exit;
  228. }
  229. mysqli_set_charset($conn, "utf8"); //,character_set_client=binary,sql_mode='';
  230. $version = mysqli_get_server_info($conn);
  231. if ($version < 5.1) {
  232. $arr['msg'] = '数据库版本太低! 必须5.1以上';
  233. echo json_encode($arr);
  234. exit;
  235. }
  236. if (!mysqli_select_db($conn, $dbName)) {
  237. //创建数据时同时设置编码
  238. if (!mysqli_query($conn, "CREATE DATABASE IF NOT EXISTS `" . $dbName . "` DEFAULT CHARACTER SET utf8;")) {
  239. $arr['msg'] = '数据库 ' . $dbName . ' 不存在,也没权限创建新的数据库!';
  240. echo json_encode($arr);
  241. exit;
  242. }
  243. if ($n == -1) {
  244. $arr['n'] = 0;
  245. $arr['msg'] = "成功创建数据库:{$dbName}<br>";
  246. echo json_encode($arr);
  247. exit;
  248. }
  249. mysqli_select_db($conn, $dbName);
  250. }
  251. //读取数据文件
  252. $sqldata = file_get_contents(SITE_DIR . 'install/' . $sqlFile);
  253. $sqlFormat = sql_split($sqldata, $dbPrefix);
  254. //创建写入sql数据库文件到库中 结束
  255. /**
  256. * 执行SQL语句
  257. */
  258. $counts = count($sqlFormat);
  259. for ($i = $n; $i < $counts; $i++) {
  260. $sql = trim($sqlFormat[$i]);
  261. if (strstr($sql, 'CREATE TABLE')) {
  262. preg_match('/CREATE TABLE (IF NOT EXISTS)? `eb_([^ ]*)`/is', $sql, $matches);
  263. mysqli_query($conn, "DROP TABLE IF EXISTS `$matches[2]");
  264. $sql = str_replace('`eb_', '`' . $dbPrefix, $sql);//替换表前缀
  265. $ret = mysqli_query($conn, $sql);
  266. if ($ret) {
  267. $message = '<li><span class="correct_span">&radic;</span>创建数据表[' . $dbPrefix . $matches[2] . ']完成!<span style="float: right;">' . date('Y-m-d H:i:s') . '</span></li> ';
  268. } else {
  269. $err = mysqli_error($conn);
  270. $message = '<li><span class="correct_span error_span">&radic;</span>创建数据表[' . $dbPrefix . $matches[2] . ']失败!失败原因:' . $err . '<span style="float: right;">' . date('Y-m-d H:i:s') . '</span></li>';
  271. }
  272. $i++;
  273. $arr = array('n' => $i, 'msg' => $message);
  274. echo json_encode($arr);
  275. exit;
  276. } else {
  277. if (trim($sql) == '')
  278. continue;
  279. $sql = str_replace('`eb_', '`' . $dbPrefix, $sql);//替换表前缀
  280. $ret = mysqli_query($conn, $sql);
  281. $message = '';
  282. $arr = array('n' => $i, 'msg' => $message);
  283. // echo json_encode($arr); exit;
  284. }
  285. }
  286. // 清空测试数据
  287. if (!$_POST['demo']) {
  288. $result = mysqli_query($conn, "show tables");
  289. $tables = mysqli_fetch_all($result);//参数MYSQL_ASSOC、MYSQLI_NUM、MYSQLI_BOTH规定产生数组类型
  290. $bl_table = array('eb_system_admin'
  291. , 'eb_system_role'
  292. , 'eb_system_config'
  293. , 'eb_system_config_tab'
  294. , 'eb_system_menus'
  295. , 'eb_system_file'
  296. , 'eb_express'
  297. , 'eb_system_group'
  298. , 'eb_system_group_data'
  299. , 'eb_template_message'
  300. , 'eb_shipping_templates'
  301. , "eb_shipping_templates_region"
  302. , "eb_shipping_templates_free"
  303. , 'eb_system_city'
  304. , 'eb_diy'
  305. , 'eb_cache');
  306. foreach ($bl_table as $k => $v) {
  307. $bl_table[$k] = str_replace('eb_', $dbPrefix, $v);
  308. }
  309. foreach ($tables as $key => $val) {
  310. if (!in_array($val[0], $bl_table)) {
  311. mysqli_query($conn, "truncate table " . $val[0]);
  312. }
  313. }
  314. delFile(APP_DIR . '/uploads'); // 清空测试图片
  315. }
  316. //读取配置文件,并替换真实配置数据1
  317. $strConfig = file_get_contents(SITE_DIR . 'install/' . $configFile);
  318. $strConfig = str_replace('#DB_HOST#', $dbHost, $strConfig);
  319. $strConfig = str_replace('#DB_NAME#', $dbName, $strConfig);
  320. $strConfig = str_replace('#DB_USER#', $dbUser, $strConfig);
  321. $strConfig = str_replace('#DB_PWD#', $dbPwd, $strConfig);
  322. $strConfig = str_replace('#DB_PORT#', $_POST['dbport'], $strConfig);
  323. $strConfig = str_replace('#DB_PREFIX#', $dbPrefix, $strConfig);
  324. $strConfig = str_replace('#DB_CHARSET#', 'utf8', $strConfig);
  325. // $strConfig = str_replace('#DB_DEBUG#', false, $strConfig);
  326. //redis数据库信息
  327. $rbhost = $_POST['rbhost'] ?? '127.0.0.1';
  328. $rbport = $_POST['rbport'] ?? '6379';
  329. $rbpw = $_POST['rbpw'] ?? '';
  330. $rbselect = $_POST['rbselect'] ?? 0;
  331. $strConfig = str_replace('#RB_HOST#', $rbhost, $strConfig);
  332. $strConfig = str_replace('#RB_PORT#', $rbport, $strConfig);
  333. $strConfig = str_replace('#RB_PWD#', $rbpw, $strConfig);
  334. $strConfig = str_replace('#RB_SELECT#', $rbselect, $strConfig);
  335. //需改队列名称
  336. $strConfig = str_replace('#QUEUE_NAME#', uniqid(), $strConfig);
  337. @chmod(APP_DIR . '/.env', 0777); //数据库配置文件的地址
  338. @file_put_contents(APP_DIR . '/.env', $strConfig); //数据库配置文件的地址
  339. //读取配置文件,并替换换配置
  340. // $strConfig = file_get_contents(SITE_DIR . '/application/config.php');
  341. // $strConfig = str_replace('CRMEB_cache_prefix', $uniqid_str, $strConfig);
  342. // @chmod(SITE_DIR . '/application/config.php',0777); //配置文件的地址
  343. // @file_put_contents(SITE_DIR . '/application/config.php', $strConfig); //配置文件的地址
  344. //更新网站配置信息2
  345. //插入管理员表字段tp_admin表
  346. $time = time();
  347. $ip = get_client_ip();
  348. $ip = empty($ip) ? "0.0.0.0" : $ip;
  349. $password = password_hash($_POST['manager_pwd'], PASSWORD_BCRYPT);
  350. mysqli_query($conn, "truncate table {$dbPrefix}system_admin");
  351. $addadminsql = "INSERT INTO `{$dbPrefix}system_admin` (`id`, `account`, `pwd`, `real_name`, `roles`, `last_ip`, `last_time`, `add_time`, `login_count`, `level`, `status`, `is_del`) VALUES
  352. (1, '" . $username . "', '" . $password . "', 'admin', '1', '" . $ip . "',$time , $time, 0, 0, 1, 0)";
  353. $res = mysqli_query($conn, $addadminsql);
  354. $res2 = true;
  355. if (isset($_SERVER['SERVER_NAME'])) {
  356. $site_url = '\'"http://' . $_SERVER['SERVER_NAME'] . '"\'';
  357. $res2 = mysqli_query($conn, 'UPDATE `' . $dbPrefix . 'system_config` SET `value`=' . $site_url . ' WHERE `menu_name`="site_url"');
  358. }
  359. if ($res) {
  360. $message = '成功添加管理员<br />成功写入配置文件<br>安装完成.';
  361. $arr = array('n' => 999999, 'msg' => $message);
  362. echo json_encode($arr);
  363. exit;
  364. } else {
  365. $message = '添加管理员失败<br />成功写入配置文件<br>安装完成.';
  366. $arr = array('n' => 999999, 'msg' => $message);
  367. echo json_encode($arr);
  368. exit;
  369. }
  370. }
  371. include_once("./templates/step4.php");
  372. exit();
  373. case '5':
  374. $ip = get_client_ip();
  375. $host = $_SERVER['HTTP_HOST'];
  376. $curent_version = getversion();
  377. $version = trim($curent_version['version']);
  378. installlog();
  379. include_once("./templates/step5.php");
  380. @touch('./install.lock');
  381. exit();
  382. }
  383. //读取版本号
  384. function getversion()
  385. {
  386. $version_arr = [];
  387. $curent_version = @file(APP_DIR . '.version');
  388. foreach ($curent_version as $val) {
  389. list($k, $v) = explode('=', $val);
  390. $version_arr[$k] = $v;
  391. }
  392. return $version_arr;
  393. }
  394. //写入安装信息
  395. function installlog()
  396. {
  397. $mt_rand_str = sp_random_string(6);
  398. $str_constant = "<?php" . PHP_EOL . "define('INSTALL_DATE'," . time() . ");" . PHP_EOL . "define('SERIALNUMBER','" . $mt_rand_str . "');";
  399. @file_put_contents(APP_DIR . '.constant', $str_constant);
  400. }
  401. //判断权限
  402. function testwrite($d)
  403. {
  404. if (is_file($d)) {
  405. if (is_writeable($d)) {
  406. return true;
  407. }
  408. return false;
  409. } else {
  410. $tfile = "_test.txt";
  411. $fp = @fopen($d . "/" . $tfile, "w");
  412. if (!$fp) {
  413. return false;
  414. }
  415. fclose($fp);
  416. $rs = @unlink($d . "/" . $tfile);
  417. if ($rs) {
  418. return true;
  419. }
  420. return false;
  421. }
  422. }
  423. function sql_split($sql, $tablepre)
  424. {
  425. if ($tablepre != "tp_")
  426. $sql = str_replace("tp_", $tablepre, $sql);
  427. $sql = preg_replace("/TYPE=(InnoDB|MyISAM|MEMORY)( DEFAULT CHARSET=[^; ]+)?/", "ENGINE=\\1 DEFAULT CHARSET=utf8", $sql);
  428. $sql = str_replace("\r", "\n", $sql);
  429. $ret = array();
  430. $num = 0;
  431. $queriesarray = explode(";\n", trim($sql));
  432. unset($sql);
  433. foreach ($queriesarray as $query) {
  434. $ret[$num] = '';
  435. $queries = explode("\n", trim($query));
  436. $queries = array_filter($queries);
  437. foreach ($queries as $query) {
  438. $str1 = substr($query, 0, 1);
  439. if ($str1 != '#' && $str1 != '-')
  440. $ret[$num] .= $query;
  441. }
  442. $num++;
  443. }
  444. return $ret;
  445. }
  446. function _dir_path($path)
  447. {
  448. $path = str_replace('\\', '/', $path);
  449. if (substr($path, -1) != '/')
  450. $path = $path . '/';
  451. return $path;
  452. }
  453. // 获取客户端IP地址
  454. function get_client_ip()
  455. {
  456. static $ip = NULL;
  457. if ($ip !== NULL)
  458. return $ip;
  459. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  460. $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  461. $pos = array_search('unknown', $arr);
  462. if (false !== $pos)
  463. unset($arr[$pos]);
  464. $ip = trim($arr[0]);
  465. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  466. $ip = $_SERVER['HTTP_CLIENT_IP'];
  467. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  468. $ip = $_SERVER['REMOTE_ADDR'];
  469. }
  470. // IP地址合法验证
  471. $ip = (false !== ip2long($ip)) ? $ip : '0.0.0.0';
  472. return $ip;
  473. }
  474. function dir_create($path, $mode = 0777)
  475. {
  476. if (is_dir($path))
  477. return TRUE;
  478. $ftp_enable = 0;
  479. $path = dir_path($path);
  480. $temp = explode('/', $path);
  481. $cur_dir = '';
  482. $max = count($temp) - 1;
  483. for ($i = 0; $i < $max; $i++) {
  484. $cur_dir .= $temp[$i] . '/';
  485. if (@is_dir($cur_dir))
  486. continue;
  487. @mkdir($cur_dir, 0777, true);
  488. @chmod($cur_dir, 0777);
  489. }
  490. return is_dir($path);
  491. }
  492. function dir_path($path)
  493. {
  494. $path = str_replace('\\', '/', $path);
  495. if (substr($path, -1) != '/')
  496. $path = $path . '/';
  497. return $path;
  498. }
  499. function sp_password($pw, $pre)
  500. {
  501. $decor = md5($pre);
  502. $mi = md5($pw);
  503. return substr($decor, 0, 12) . $mi . substr($decor, -4, 4);
  504. }
  505. function sp_random_string($len = 8)
  506. {
  507. $chars = array(
  508. "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
  509. "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
  510. "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
  511. "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
  512. "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
  513. "3", "4", "5", "6", "7", "8", "9"
  514. );
  515. $charsLen = count($chars) - 1;
  516. shuffle($chars); // 将数组打乱
  517. $output = "";
  518. for ($i = 0; $i < $len; $i++) {
  519. $output .= $chars[mt_rand(0, $charsLen)];
  520. }
  521. return $output;
  522. }
  523. // 递归删除文件夹
  524. function delFile($dir, $file_type = '')
  525. {
  526. if (is_dir($dir)) {
  527. $files = scandir($dir);
  528. //打开目录 //列出目录中的所有文件并去掉 . 和 ..
  529. foreach ($files as $filename) {
  530. if ($filename != '.' && $filename != '..') {
  531. if (!is_dir($dir . '/' . $filename)) {
  532. if (empty($file_type)) {
  533. unlink($dir . '/' . $filename);
  534. } else {
  535. if (is_array($file_type)) {
  536. //正则匹配指定文件
  537. if (preg_match($file_type[0], $filename)) {
  538. unlink($dir . '/' . $filename);
  539. }
  540. } else {
  541. //指定包含某些字符串的文件
  542. if (false != stristr($filename, $file_type)) {
  543. unlink($dir . '/' . $filename);
  544. }
  545. }
  546. }
  547. } else {
  548. delFile($dir . '/' . $filename);
  549. rmdir($dir . '/' . $filename);
  550. }
  551. }
  552. }
  553. } else {
  554. if (file_exists($dir)) unlink($dir);
  555. }
  556. }
  557. ?>