1. /**
    2. * 创建记日志目录
    3. * @param undefined $path
    4. *
    5. * @return
    6. */
    7. public static function creatDir($path){
    8. $arr = explode('/',$path);
    9. $pathStr = '';
    10. if($arr){
    11. foreach($arr as $val){
    12. $pathStr .= $val.'/';
    13. if(!to8to_is_dir($pathStr)){
    14. to8to_mkdir($pathStr);
    15. }
    16. }
    17. }
    18. }
    19. <?php
    20. include_once(ROOT.'/gb_php/to8tocurl.class.php');
    21. /**
    22. * @param $path 文件路径
    23. * @param $method 请求方式
    24. * @return 返回请求数组
    25. * 连接有效服务器
    26. */
    27. function to8to_file_server($path,$method='get')
    28. {
    29. global $_CFG;
    30. $serverconf = $_CFG['fileServer'];
    31. if(empty($serverconf))
    32. {
    33. //throw new Exception('连接不上');
    34. }
    35. $curl = new to8toCurl();
    36. foreach($serverconf as $val)
    37. {
    38. $recurl = $curl->curl($val,$path,$method);
    39. if($recurl['httpCode'] == 200)
    40. {
    41. return $recurl;
    42. }
    43. }
    44. }
    45. //获取文件修改时间
    46. function to8to_filemtime($path)
    47. { checkRoot($path);
    48. if(defined('FILE_SERVER') && strstr($path,ROOT.'/pic/')!==false)
    49. {
    50. $redata=to8to_file_server(array('act'=>'getInfo','path'=>$path),'get');
    51. $data = json_decode($redata['data'],true);
    52. $time = $data["utime"]?$data["utime"]:false;
    53. }
    54. else
    55. {
    56. $time = filemtime($path);
    57. }
    58. return $time;
    59. }
    60. //获取文件是否存在
    61. function to8to_is_file($path)
    62. { checkRoot($path);
    63. if(defined('FILE_SERVER') && strstr($path,ROOT.'/pic/')!==false)
    64. {
    65. $redata=to8to_file_server(array('act'=>'getInfo','path'=>$path),'get');
    66. $data = json_decode($redata['data'],true);
    67. $is_file = $data["file_exists"];
    68. $is_file = $is_file ? ($data["filetype"]==0?true:false) : false;
    69. }
    70. else
    71. {
    72. $is_file = is_file($path);
    73. }
    74. return $is_file;
    75. }
    76. /**
    77. * @param $path
    78. * @return bool
    79. * 文件是否存在
    80. */
    81. function to8to_file_exists($path)
    82. { checkRoot($path);
    83. if(defined('FILE_SERVER') && strstr($path,ROOT.'/pic/')!==false)
    84. {
    85. $redata=to8to_file_server(array('act'=>'getInfo','path'=>$path),'get');
    86. $data = json_decode($redata['data'],true);
    87. $file_exists = $data["file_exists"] ;
    88. }
    89. else
    90. {
    91. $file_exists = file_exists($path);
    92. }
    93. return $file_exists;
    94. }
    95. /**
    96. * @param $path
    97. * @return bool
    98. * 是否是文件目录
    99. */
    100. function to8to_is_dir($path)
    101. { checkRoot($path);
    102. if(defined('FILE_SERVER') && strstr($path,ROOT.'/pic/')!==false)
    103. {
    104. $redata=to8to_file_server(array('act'=>'getInfo','path'=>$path),'get');
    105. $data = json_decode($redata['data'],true);
    106. $is_dir = $data["file_exists"];
    107. $is_dir = $is_dir ? ($data['filetype']==1?true:false):false;
    108. }
    109. else
    110. {
    111. $is_dir = is_dir($path);
    112. }
    113. return $is_dir;
    114. }
    115. /**
    116. * @param $tmpName
    117. * @param $toPath
    118. * @return bool
    119. */
    120. function to8to_move_uploaded_file($tmpName , $toPath)
    121. { checkRoot($toPath);
    122. $newExt = substr(strrchr($toPath,'.'),1);
    123. if(strtolower($newExt) == 'php' || strtolower($newExt) =='php5')
    124. {
    125. return false;
    126. }
    127. $returnstr = move_uploaded_file($tmpName , $toPath);
    128. if(defined('FILE_SERVER')&& strstr($toPath,ROOT.'/pic/')!==false)
    129. {
    130. $redata=to8to_file_server(array('act'=>'upInfo','path'=>$toPath),'get');
    131. }
    132. return $returnstr;
    133. }
    134. /**
    135. * 创建目录
    136. * @return bool
    137. * @author yaowenqiang
    138. */
    139. function to8to_mkdir($pathname,$mode = 0777,$recursive = false )
    140. {
    141. return mkdir($pathname,$mode,$recursive);
    142. }
    143. /**
    144. * 清空状态缓存
    145. *
    146. * @return void
    147. * @author yaowenqiang
    148. */
    149. function to8to_clearstatcache()
    150. {
    151. clearstatcache();
    152. }
    153. /**
    154. * 文件拷贝
    155. *
    156. * @return bool
    157. * @author yaowenqiang
    158. */
    159. function to8to_copy($source,$dest)
    160. {
    161. return copy($source,$dest);
    162. }
    163. /**
    164. * 删除文件
    165. *
    166. * @return bool
    167. * @author yaowenqiang
    168. */
    169. function to8to_delete($filename)
    170. {
    171. return unlink($filename);
    172. }
    173. /**
    174. * 删除文件
    175. *
    176. * @return bool
    177. * @author yaowenqiang
    178. */
    179. function to8to_unlink($filename)
    180. { checkRoot($filename);
    181. return unlink($filename);
    182. }
    183. /**
    184. * 关闭文件
    185. *
    186. * @return bool
    187. * @author yaowenqiang
    188. */
    189. function to8to_fclose($handle)
    190. {
    191. return fclose($handle);
    192. }
    193. /**
    194. * 测试文件指针是否到了文件结束的位置
    195. *
    196. * @return bool
    197. * @author yaowenqiang
    198. */
    199. function to8to_feof($handle)
    200. {
    201. return feof($handle);
    202. }
    203. /**
    204. * 从文件指针中读取字符
    205. *
    206. * @return string
    207. * @author yaowenqiang
    208. */
    209. function to8to_fgetc($handle)
    210. {
    211. return fgetc($handle);
    212. }
    213. /**
    214. * 从文件指针中读入一行并解析 CSV 字段
    215. *
    216. * @return array
    217. * @author yaowenqiang
    218. */
    219. function to8to_fgetcsv($handle,$length=0,$delimiter=',',$enclosure='"',$escape='\\')
    220. {
    221. return fgetcsv($handle,$length,$delimiter,$enclosure,$escape);
    222. }
    223. /**
    224. * 从文件指针中读取一行
    225. *
    226. * @return void
    227. * @author yaowenqiang
    228. */
    229. function to8to_fgets($handle,$length=0)
    230. {
    231. if($length>0)
    232. {
    233. return fgets($handle,$length);
    234. }
    235. return fgets($handle);
    236. }
    237. /**
    238. * 从文件指针中读取一行并过滤掉 HTML 标记
    239. *
    240. * @return string
    241. * @author yaowenqiang
    242. */
    243. function to8to_fgetss($handle,$length=0,$allowable_tags='')
    244. { if($length>0)
    245. {
    246. return fgetss($handle,$length,$allowable_tags);
    247. }
    248. return fgetss($handle);
    249. }
    250. /**
    251. * 取得文件类型
    252. *
    253. * @return string
    254. * @author yaowenqiang
    255. */
    256. function to8to_filetype($filename)
    257. { checkRoot($filename);
    258. return filetype($filename);
    259. }
    260. /**
    261. * 轻便的咨询文件锁定
    262. *
    263. * @return string
    264. * @author yaowenqiang
    265. */
    266. function to8to_flock($handle,$operation,$wouldblock=true)
    267. {
    268. return flock($handle,$operation,$wouldblock);
    269. }
    270. /**
    271. * 打开文件或者 URL
    272. *
    273. * @return string
    274. * @author yaowenqiang
    275. */
    276. function to8to_fopen($filename, $mode, $use_include_path = false, $context = null)
    277. { checkRoot($filename);
    278. if (!$filename || preg_match("/\.\./", $filename)) {
    279. /*日志记录路径*/
    280. $logName = ROOT.'/syslog/mingxilog/filePathCheck'.date("Y-m-d").'.log';
    281. $f = fopen($logName, 'a');
    282. $fun_msg = debug_backtrace();
    283. $log = '[含点点]'.date('H:i:s').json_encode($fun_msg);
    284. fwrite($f, $log."\n");
    285. fclose($f);
    286. }
    287. if ($context == null) {
    288. return fopen($filename, $mode, $use_include_path);
    289. } else {
    290. return fopen($filename, $mode, $use_include_path, $context);
    291. }
    292. }
    293. /**
    294. * 输出文件指针处的所有剩余数据
    295. *
    296. * @return string
    297. * @author yaowenqiang
    298. */
    299. function to8to_fpassthru($handle)
    300. {
    301. return fpassthru($handle);
    302. }
    303. /**
    304. * 将行格式化为 CSV 并写入文件指针
    305. *
    306. * @return string
    307. * @author yaowenqiang
    308. */
    309. function to8to_fputcsv($handle,$fields,$delimiter=',',$enclosure='"')
    310. {
    311. return fputcsv($handle,$fields,$delimiter,$enclosure);
    312. }
    313. /**
    314. * 将行格式化为 CSV 并写入文件指针
    315. *
    316. * @return string
    317. * @author yaowenqiang
    318. */
    319. function to8to_fputs($file,$string,$length=0)
    320. {
    321. if($length>0)
    322. {
    323. return fputs($file,$string,$length);
    324. }
    325. return fputs($file,$string);
    326. }
    327. /**
    328. * 读取文件(可安全用于二进制文件)
    329. *
    330. * @return string
    331. * @author yaowenqiang
    332. */
    333. function to8to_fread($handle,$length)
    334. {
    335. return fread($handle,$length);
    336. }
    337. /**
    338. * 从文件中格式化输入
    339. *
    340. * @return string
    341. * @author yaowenqiang
    342. */
    343. function to8to_fscanf($handle,$length)
    344. {
    345. return fscanf($handle,$length);
    346. }
    347. /**
    348. * 通过已打开的文件指针取得文件信息
    349. *
    350. * @return string
    351. * @author yaowenqiang
    352. */
    353. function to8to_fstat($handle)
    354. {
    355. return fstat($handle);
    356. }
    357. /**
    358. * 写入文件(可安全用于二进制文件)
    359. *
    360. * @return int
    361. * @author yaowenqiang
    362. */
    363. function to8to_fwrite($handle,$string,$length=0)
    364. { if($length>0)
    365. {
    366. return fwrite($handle,$string,$length);
    367. }
    368. return fwrite($handle,$string);
    369. }
    370. /**
    371. * 将文件截断到给定的长度
    372. *
    373. * @return bool
    374. * @author yaowenqiang
    375. */
    376. function to8to_ftruncate($handle,$size)
    377. {
    378. return ftruncate($handle,$size);
    379. }
    380. /**
    381. * 寻找与模式匹配的文件路径
    382. *
    383. * @return array
    384. * @author yaowenqiang
    385. */
    386. function to8to_glob($pattern,$flag=0)
    387. {
    388. return glob($pattern,$flag);
    389. }
    390. /**
    391. * 判断给定文件名是否为一个符号连接
    392. *
    393. * @return bool
    394. * @author yaowenqiang
    395. */
    396. function to8to_is_link($filename)
    397. { checkRoot($filename);
    398. return is_link($filename);
    399. }
    400. /**
    401. * 判断给定的文件名是否可写
    402. *
    403. * @return bool
    404. * @author yaowenqiang
    405. */
    406. function to8to_is_writable($filename)
    407. { checkRoot($filename);
    408. return is_writable($filename);
    409. }
    410. /**
    411. * 判断给定文件名是否可读
    412. *
    413. * @return bool
    414. * @author yaowenqiang
    415. */
    416. function to8to_is_readable($filename)
    417. { checkRoot($filename);
    418. return is_readable($filename);
    419. }
    420. /**
    421. * 判断文件是否是通过 HTTP POST 上传的
    422. *
    423. * @return bool
    424. * @author yaowenqiang
    425. */
    426. function to8to_is_uploaed_file($filename)
    427. { checkRoot($filename);
    428. return is_uploaed_file($filename);
    429. }
    430. /**
    431. * 输出一个文件
    432. *
    433. * @return bool
    434. * @author yaowenqiang
    435. */
    436. function to8to_readfile($filename,$include_path=false,$context='')
    437. { checkRoot($filename);
    438. return readfile($filename);
    439. }
    440. /**
    441. * 返回规范化的绝对路径名
    442. *
    443. * @return string
    444. * @author yaowenqiang
    445. */
    446. function to8to_realpath($path)
    447. { checkRoot($path);
    448. return realpath($path);
    449. }
    450. /**
    451. * 重命名一个文件或目录
    452. *
    453. * @return bool
    454. * @author yaowenqiang
    455. */
    456. function to8to_rename($oldname,$newname)
    457. {
    458. return rename($oldname,$newname);
    459. }
    460. /**
    461. * 倒回文件指针的位置
    462. *
    463. * @return bool
    464. * @author yaowenqiang
    465. */
    466. function to8to_rewind($handle)
    467. {
    468. return rewind($handle);
    469. }
    470. /**
    471. * 删除目录
    472. *
    473. * @return bool
    474. * @author yaowenqiang
    475. */
    476. function to8to_rmdir($dirname)
    477. {
    478. return rmdir($dirname);
    479. }
    480. /**
    481. * 建立一个临时文件
    482. *
    483. * @return resource
    484. * @author yaowenqiang
    485. */
    486. function to8to_tmpfile()
    487. {
    488. return tmpfile();
    489. }
    490. /**
    491. * 设定文件的访问和修改时间
    492. *
    493. * @return resource
    494. * @author yaowenqiang
    495. */
    496. function to8to_touch($filename,$time=0,$atime=0)
    497. { checkRoot($filename);
    498. if($time>0||$atime>0)
    499. { if($time<=0)
    500. {
    501. $time = time();
    502. }
    503. if($atime<=0)
    504. {
    505. $atime = time();
    506. }
    507. return touch($filename,$time,$atime);
    508. }
    509. return touch($filename);
    510. }
    511. /**
    512. * 设定文件的访问和修改时间
    513. *
    514. * @return resource
    515. * @author yaowenqiang
    516. */
    517. function to8to_umask($mask=0777)
    518. {
    519. return umask($mask);
    520. }
    521. /*函数返回文件路径的部分
    522. * @author wong
    523. * @parm string string
    524. * @return filename
    525. */
    526. function to8to_basename($path,$suffix='')
    527. {
    528. return basename($path);
    529. }
    530. /*函数文件所属组
    531. *@author wong
    532. *@return bool
    533. * */
    534. function to8to_chgrp($file,$group)
    535. {
    536. return chgrp($file,$group);
    537. }
    538. /*函数改变文件的模式
    539. * @author wong
    540. * @return bool
    541. * */
    542. function to8to_chomd($file,$mod=0755)
    543. {
    544. return chmod($file,$mod);
    545. }
    546. /*函数改变文件所有者
    547. * @author wong
    548. * @return bool
    549. * */
    550. function to8to_chown($file,$user)
    551. {
    552. return chown($file,$user);
    553. }
    554. /*函数返回文件目录部分
    555. * @author wong
    556. * @return bool
    557. * */
    558. function to8to_dirname($path)
    559. {
    560. return dirname($path);
    561. }
    562. /*函数返回目录可用空间
    563. * @author wong
    564. * @return bool
    565. * */
    566. function to8to_disk_free_space($directory)
    567. {
    568. return disk_free_space($directory);
    569. }
    570. /* 函数将缓冲内容输出到文件
    571. * @author wong
    572. * @return bool
    573. * */
    574. function to8to_fflush($file)
    575. {
    576. return fflush($file);
    577. }
    578. /*函数返回一个目录磁盘总大小
    579. * @author wong
    580. * @return bool
    581. * */
    582. function to8to_diskfreespace($directory)
    583. {
    584. return diskfreespace($directory);
    585. }
    586. /**
    587. * 自己封装的_file_put_contents函数
    588. * 对写入的文件后缀做了限制
    589. * @param $filename
    590. * @param $data
    591. * @param null $flags
    592. * @param null $context
    593. * @return int|string
    594. */
    595. function to8to_file_put_contents($filename, $data, $flags = null, $context = null)
    596. {
    597. $ext = getFileExt($filename);
    598. if (!$filename || $ext == 'php')
    599. {
    600. return '';
    601. }
    602. return file_put_contents($filename, $data, $flags, $context);
    603. }
    604. /**
    605. * 自己封装的_file_get_contents函数
    606. * 主要对一些file://协议做了过滤
    607. * @param $filename
    608. * @param null $flags
    609. * @param null $context
    610. * @param null $offset
    611. * @param null $maxlen
    612. * @return string
    613. */
    614. function to8to_file_get_contents($filename, $flags = null, $context = null, $offset = null, $maxlen = null)
    615. {
    616. if (!$filename || preg_match("/(\.\.|file:\/\/)/", $filename)) {
    617. return '';
    618. }
    619. if ($maxlen === null) {
    620. return file_get_contents($filename, $flags, $context, $offset);
    621. } else {
    622. return file_get_contents($filename, $flags, $context, $offset, $maxlen);
    623. }
    624. }
    625. /*函数返回文件上次访问时间
    626. * @author wong
    627. * @return int
    628. * */
    629. function to8to_fileatime($filename)
    630. {
    631. return fileatime($filename);
    632. }
    633. /*函数返回文件修改时间
    634. * @author wong
    635. * @return int
    636. * */
    637. function to8to_filectime($filename)
    638. {
    639. return filectime($filename);
    640. }
    641. /*函数返回文件组ID
    642. * @author wong
    643. * @return int
    644. * */
    645. function to8to_filegroup($filename)
    646. {
    647. return filegroup($filename);
    648. }
    649. /*函数返回文件inode编号
    650. * @author wong
    651. * @return int bool
    652. * */
    653. function to8to_fileinode($filename)
    654. {
    655. return fileinode($filename);
    656. }
    657. /*函数返回文件的所有者
    658. * @author wong
    659. * @author int
    660. * */
    661. function to8to_fileowner($filename)
    662. {
    663. return fileowner($filename);
    664. }
    665. /*函数返回文件或目录的权限
    666. * @author wong
    667. * @return int
    668. * */
    669. function to8to_fileperms($filename)
    670. {
    671. return fileperms($filename);
    672. }
    673. /*函数返回文件大小
    674. * @author wong
    675. * @return int
    676. * */
    677. function to8to_filesize($filename)
    678. {
    679. return filesize($filename);
    680. }
    681. /*函数返回文件大小
    682. * @author wong
    683. * @return int
    684. * */
    685. function to8to_fnmatch($pattern,$string,$flags=0)
    686. {
    687. return fnmatch($pattern,$string,$flags);
    688. }
    689. /*函数检查制定的文件是否可执行
    690. * @author wong
    691. * @return bool
    692. * */
    693. function to8to_is_executable($file)
    694. {
    695. return is_executable($file);
    696. }
    697. /*函数改变文件所属组
    698. * @author wong
    699. * @return bool
    700. * */
    701. function to8to_ichgrp($file,$group)
    702. {
    703. return ichgrp($file,$group);
    704. }
    705. /*函数创建一个硬连接
    706. * @author wong
    707. * @return bool
    708. * */
    709. function to8to_link($target,$link)
    710. {
    711. return link($target,$link);
    712. }
    713. /*函数返回连接的信息
    714. * @author wong
    715. * @author int
    716. * */
    717. function to8to_linkinfo($path)
    718. {
    719. return linkinfo($path);
    720. }
    721. /*函数解析一个配置文件,并以数组的形式返回其中的设置
    722. * @author wong
    723. * @return array
    724. * */
    725. function to8to_parse_ini_file($file,$process_sections=true)
    726. {
    727. return parse_ini_file($file,$process_sections);
    728. }
    729. /*
    730. * @author wong
    731. * @return array
    732. * */
    733. function to8to_parse_ini_string($ini,$process_sections=false,$scanner_mode=INI_SCANNER_NORMAL)
    734. {
    735. return parse_ini_string($ini,$process_sections,$scanner_mode);
    736. }
    737. /*函数关闭有popen()打开的管道
    738. * @author wong
    739. * @return int
    740. * */
    741. function to8to_pclose($pipe)
    742. {
    743. return pclose($pipe);
    744. }
    745. /*函数打开进程文件指针
    746. * @author wong
    747. * @return resource
    748. * */
    749. function to8to_popen($command,$mode)
    750. {
    751. // return popen($command,$mode);
    752. }
    753. /*函数返回符号连接指向的目标
    754. * @author wong
    755. * @return string
    756. * */
    757. function to8to_readlink($linkPath)
    758. {
    759. return readlink($linkPath);
    760. }
    761. /*
    762. * @author wong
    763. * @return init
    764. * */
    765. function to8to_realpath_cache_size()
    766. {
    767. return realpath_cache_size();
    768. }
    769. /*返回规范化的绝对路径
    770. * @author wong
    771. * @return array
    772. * */
    773. function to8to_realpath_cache_get()
    774. {
    775. return realpath_cache_get();
    776. }
    777. /*返回关于文件的信息
    778. * @author wong
    779. * @return string
    780. * */
    781. function to8to_stat($file)
    782. {
    783. return stat($file);
    784. }
    785. /*返回函数设置打开文件缓冲大小
    786. * @author wong
    787. * @return int
    788. * */
    789. function to8to_set_file_buffer($file,$buffer)
    790. {
    791. return set_file_buffer($file,$buffer);
    792. }
    793. /*创建符号连接
    794. * @author wong
    795. * @return bool
    796. * */
    797. function to8to_symlink($target,$link)
    798. {
    799. return symlink($target,$link);
    800. }
    801. /*函数创建具有唯一文件名的临时文件
    802. * @author wong
    803. * @return strimg
    804. * */
    805. function to8to_tempnam($target,$link)
    806. {
    807. return tempnam($target,$link);
    808. }
    809. /*函数(w+)创建具有唯一文件名的临时文件
    810. * @author wong
    811. * @return string
    812. * */
    813. function to8to_tempfile($target,$link)
    814. {
    815. return tmpfile($target,$link);
    816. }
    817. /*函数读取一个
    818. * @author wong
    819. * @return string
    820. * */
    821. function to8to_file($path,$inclue_path=0,$context=null)
    822. {
    823. return file($path,$inclue_path,$context);
    824. }
    825. /*检查是否存在是否为ROOT开头,不是则记录日志
    826. * $path string
    827. * */
    828. function checkRoot($path)
    829. {
    830. if ( strstr($path,ROOT)==false)
    831. {
    832. /*日志记录路径*/
    833. $logName = ROOT.'/syslog/mingxilog/filePathCheck'.date("Y-m-d").'.log';
    834. $f = fopen($logName, 'a');
    835. $fun_msg = debug_backtrace();
    836. $fun_msg = is_array($fun_msg)?$fun_msg:array();
    837. $log = '[路径非ROOT开头]'.date('H:i:s').json_encode($fun_msg);
    838. fwrite($f, $log."\n");
    839. fclose($f);
    840. }
    841. }