在PHP中包含文件的最佳方法?

my file paths was like

mysite/projectname/folder1/abc1/abc2/myfile.php

now i am working in the path

mysite/projectname/folder1/xyz1/xyz2/workingfile.php

at present i have to include myfile.php on workingfile.php

i was tried with

include(../../myfile.php)

its working.

my doubt is what is the best way to include this file ?

have seen example1 example2

Use dirname():

require_once(dirname(dirname(dirname(__FILE__))) . '/myfile.php');

Chaining them together will grab parents. The above code would be the equivalent of:

require_once('../../myfile.php');

Alternatively, you could also do this with a windows-friendly option (if you for some reason want your code to work on a windows machine):

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'myfile.php');