Relative include files

前端 未结 3 1577
Happy的楠姐
Happy的楠姐 2020-12-03 12:59

I have a file

workers/activity/bulk_action.php which includes a file

include(\'../../classes/aclass.php\');

Inside aclass.php it d

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 13:45

    Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include() will finally check in the calling script's own directory and the current working directory before failing.

    You can use dirname(__FILE__) to get a path to the directory where the currently executed script resides:

    include(dirname(dirname(__FILE__)) . '/tcpdf/config/lang/eng.php');
    

    (since PHP 5.3, you can use __DIR__)

    Or, define a constant in the first file that points to the root directory and use it in your includes.

提交回复
热议问题