FileModule.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. namespace RTP\Module;
  19. class FileModule
  20. {
  21. /**
  22. * 自动在用户目录下面创建空白index.html文件,用于保护文件目录
  23. */
  24. public static function createSecurityIndex()
  25. {
  26. $path = PATH_APP;
  27. $dirs = array();
  28. $ban_dirs = array(
  29. './',
  30. '.',
  31. '../',
  32. '..'
  33. );
  34. self::getAllDirs($path, $dirs, $ban_dirs);
  35. foreach ($dirs as $dir)
  36. {
  37. if (file_exists($dir . '/index.html') || file_exists($dir . '/index.php'))
  38. continue;
  39. else
  40. {
  41. $file = fopen($dir . '/index.html', 'w');
  42. fwrite($file, '');
  43. fclose($file);
  44. }
  45. }
  46. }
  47. /**
  48. * 获取路径下的所有目录
  49. * @param String $path 目标路径
  50. * @param array $dirs 用于储存返回路径的数组
  51. * @param array $ban_dirs [可选]需要过滤的目录的相对地址的数组
  52. */
  53. public static function getAllDirs($path, array &$dirs, array &$ban_dirs = array())
  54. {
  55. $paths = scandir($path);
  56. foreach ($paths as $nextPath)
  57. {
  58. if (!in_array($nextPath, $ban_dirs) && is_dir($path . DIRECTORY_SEPARATOR . $nextPath))
  59. {
  60. $dirs[] = realpath($path . DIRECTORY_SEPARATOR . urlencode($nextPath));
  61. self::getAllDirs($path . DIRECTORY_SEPARATOR . $nextPath, $dirs, $ban_dirs);
  62. }
  63. }
  64. }
  65. /**
  66. * 获取路径下的所有文件
  67. * @param String $path 目标路径
  68. * @param array $dirs 用于储存返回路径的数组
  69. * @param array $ban_dirs [可选]需要过滤的文件名的数组
  70. */
  71. public static function getAllFiles($path, &$dirs, &$ban_dirs = array())
  72. {
  73. $paths = scandir($path);
  74. foreach ($paths as $nextPath)
  75. {
  76. if (!in_array($nextPath, $ban_dirs) && is_file($path . DIRECTORY_SEPARATOR . $nextPath))
  77. {
  78. $dirs[] = realpath($path . DIRECTORY_SEPARATOR . urlencode($nextPath));
  79. self::getAllFiles($path . DIRECTORY_SEPARATOR . $nextPath, $dirs, $ban_dirs);
  80. }
  81. }
  82. }
  83. }
  84. ?>