path_helper.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author EllisLab Dev Team
  9. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
  10. * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
  11. * @license http://codeigniter.com/user_guide/license.html
  12. * @link http://codeigniter.com
  13. * @since Version 1.0
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * CodeIgniter Path Helpers
  19. *
  20. * @package CodeIgniter
  21. * @subpackage Helpers
  22. * @category Helpers
  23. * @author EllisLab Dev Team
  24. * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
  25. */
  26. // ------------------------------------------------------------------------
  27. /**
  28. * Set Realpath
  29. *
  30. * @access public
  31. * @param string
  32. * @param bool checks to see if the path exists
  33. * @return string
  34. */
  35. if ( ! function_exists('set_realpath'))
  36. {
  37. function set_realpath($path, $check_existance = FALSE)
  38. {
  39. // Security check to make sure the path is NOT a URL. No remote file inclusion!
  40. if (preg_match("#^(http:\/\/|https:\/\/|www\.|ftp|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#i", $path))
  41. {
  42. show_error('The path you submitted must be a local server path, not a URL');
  43. }
  44. // Resolve the path
  45. if (function_exists('realpath') AND @realpath($path) !== FALSE)
  46. {
  47. $path = realpath($path).'/';
  48. }
  49. // Add a trailing slash
  50. $path = preg_replace("#([^/])/*$#", "\\1/", $path);
  51. // Make sure the path exists
  52. if ($check_existance == TRUE)
  53. {
  54. if ( ! is_dir($path))
  55. {
  56. show_error('Not a valid path: '.$path);
  57. }
  58. }
  59. return $path;
  60. }
  61. }
  62. /* End of file path_helper.php */
  63. /* Location: ./system/helpers/path_helper.php */