Here's my file tree right now.. /htdocs /htdocs/poemgenerator /htdocs/poemgenerator/index.php /htdocs/poemgenerator/poems.db /htdocs/poemgenrator/include/db.inc.php When I'm editing index.php, I include this line... require_once('/inc/db.inc.php'); But it gives me this error: Warning: require_once(/inc/db.inc.php) [function.require-once]: failed to open stream: No such file or directory in C:\Documents and Settings\Chris\My Documents\xampp\htdocs\poem_gen\index.php on line 2 Fatal error: require_once() [function.require]: Failed opening required '/inc/db.inc.php' (include_path='.;C:\Documents and Settings\Chris\My Documents\xampp\php\pear\') in C:\Documents and Settings\Chris\My Documents\xampp\htdocs\poem_gen\index.php on line 2 Why?
include path starting with / means start from the root. You can include relative paths using : the dot (.) indicates path from the current directory.
Is there a function that outputs all files in a directory? I want to see what exactly '/' is. Or do you mean '/' = 'C:\'
/ doesnt mean anything. Its just the "Windows" way of representing levels of directories. But it doesnt work in web hosting , webservers. You have to specify levels using / If your script is located in the same directory as db.inc.php, then do this If your script is located in inc directory, .. means up one level . means current directory cant make it any more simpler than this.
You can alternatively define some path constants. In the first bits of code that get executed for your application, do something like this: define ('DIR_BASE', dirname(__FILE__)); // This will return the directory from ROOT to THIS file define ('DIR_INCLUDE', DIR_BASE . DIRECTORY_SEPERATOR . 'include'); PHP: Then in other portions of your script, you can include a file like so: require_once DIR_INCLUDE . DIRECTORY_SEPERATOR . 'somefile.php'); PHP: You can choose to include a trailing slash or not in your constant based on your preference.