How to use a PHP includes across multiple directories/sub directories with relative paths

前端 未结 5 1946
旧时难觅i
旧时难觅i 2020-12-03 18:06

I\'m having difficulty with paths in a cms system I\'m attempting to build, I\'ve basically got a folder with my header.php and footer.php files inside.

These are in

5条回答
  •  孤街浪徒
    2020-12-03 18:52

    i usualy have a file called config in my application root and in it i define a constant for base path and a few others:

    define('APP_BASE_PATH', dirname(__FILE__));
    define('APP_FUNCTIONS_PATH', APP_BASE_PATH . '/functions');
    

    and i include my files like

    include (APP_BASE_PATH . 'includes/another_file.php');
    include (APP_FUNCTIONS_PATH . '/function_file.php');
    

    that way i can place my aplication in whatever directory, plus i can move files around without to much worries.

    also using full path makes the include faster

提交回复
热议问题