PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
What file did PHP start serving? Because the include path is relative to the current working directory (hint) not to the directory of the running file.
getcwd shows the working directory is not the same as the directory the script is in
However I created a testing file in the same directory and include() it from that script using a relative path, the working directory did not have an effect on that.
It would seem setting an include path of "." ( to imply relative from the including file ) has no effect ( even tho theres a comment on the manpage saying it does work ), setting an include path to an absolute path does work however, but is not desired
Here is why it behaves this way, not the working directory FYI "Files are included based on the file path given or, if none is given, the include_path specified"
so if I want to include files safely with least risk of breaking my includes later when I add files to my include path in the future, what is the best practice? The dirname( __FILE__ ) "hack"? That is the million $ question.
FYI
I am in Route.php located @
APPLICATION_PATH . '/tests/Code/Admin/config/Routes.php'
I can't put that config/ subdirectory on the include path because then it will break code that is supposed to include the other Foo.php
Personally it would make more sense to me if they did it the other way around, files without paths should always include the file in the current file's path if it exists, because now if I have /config/Bar.php and some other programmer comes in and adds /Bar.php and **** hits the fan that's not cool. Its a security concern IMO because someone could have an application where they inadvertently include a procedural script that performs some highly un-desired action
after complexity increases i used my method below. now, i am happy with this method because
it has an advantage to easily transfer your files in future & all links are absolutely will be working without much effort
i include below file to my pages
<?php
/* php include("{$rootfolder}php/examplefile.php");?> */
$rootfolder = "/home/username/public_html/"; // it can be different in your system maybe
/*<link rel="stylesheet" href="<?php echo $belowfolder; ?>css/dis.css" type="text/css">*/
$belowfolder = "/";
?>
in future if i transfer all my portal from root to folder 'transfer' then
$belowfolder becomes = "/transfer/"
$rootfolder becomes = "/home/username/public_html/transfer/";