Recently just learning PHP, in doing a small project, with a lot of require and include, by the absolute path, the relative path of the burn, finally figured out.
1, the relative path of PHP is based on the script to run, for example, A contains b,b contains C, if a, C in the same level of directory, then B contains the path of C should be relative to a, if B, C in the same level of directory, then B contains the path of C is relative to C.
2. Regardless of how the. php script is included, dirname (__file__) Gets the absolute path to the folder where the script is located.
These two rules are difficult to use accurately, at least I myself often get dizzy, so I used a more trickery way, I wrote a path.php, so very few mistakes.
<?php define (' Root_path ', DirName (__file__)); Define (' Action_path ', Root_path. /action/'); Define (' Bean_path ', Root_path. /bean/'); Define (' Dao_path ', Root_path. /dao/'); Define (' Ipadview_path ', Root_path. /ipadview/'); Define (' View_path ', Root_path. /view/'); ? >