/halogy/helpers/path_helper.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 72 lines · 24 code · 10 blank · 38 comment · 7 complexity · e40ce5e00acd860cd9e958785878e6a0 MD5 · raw file

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