sayedsohail Posted March 6, 2007 Share Posted March 6, 2007 How do i refer my file from a different directory i.e, one level above from the current location/directory. please help. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2007 Share Posted March 6, 2007 You use ".." to go up a directory tree. For example if your current directory is "/this/is/a/test" to get to a file in the directory "a", you would use "../yat.xyz". So in your case, you would write: <?php require_once('../style.css'); ?> Ken Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted March 6, 2007 Author Share Posted March 6, 2007 what about one directory below. Quote Link to comment Share on other sites More sharing options...
trq Posted March 6, 2007 Share Posted March 6, 2007 <?php require_once 'dirname/style.css'; ?> Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted March 6, 2007 Author Share Posted March 6, 2007 thanks it works. Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted March 6, 2007 Author Share Posted March 6, 2007 is there a way i could create header.php and include all the my subdirectories and than just refer in my all my webpages how do i include different paths in my header.php, please help. require_once(header.php) will automatically include those paths of my directories. Quote Link to comment Share on other sites More sharing options...
trq Posted March 6, 2007 Share Posted March 6, 2007 Take a look at the get_include_path and set_include_path functions, they may help you. Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted March 6, 2007 Author Share Posted March 6, 2007 you mean to say, if i want to include ten different paths than i have to type ten different path in my header.php file. include_path=".;c:\php\config\config.php" include_path=".;c:\php\style\stylesheet.css" include_path=".;c:\php\function\functions.js" and so on. Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted March 7, 2007 Author Share Posted March 7, 2007 you mean to say, if i want to include ten different paths than i have to type ten different path in my header.php file. include_path=".;c:\php\config\config.php" include_path=".;c:\php\style\stylesheet.css" include_path=".;c:\php\function\functions.js" and so on. Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2007 Share Posted March 7, 2007 I don't know where you got that from but a path refers to a directory, not a file. You would use something like.... <?php set_include_path( get_include_path(). PATH_SEPERATOR.'c:\php\config'. PATH_SEPERATOR.'c:\php\style'. PATH_SEPERATOR.'c:\php\function' ); ?> And yes, of course you need to add each directory you'll need. Quote Link to comment Share on other sites More sharing options...
nloding Posted March 7, 2007 Share Posted March 7, 2007 The best way I've found is to use a single INCLUDES directory, or single STYLES directory (whatever) then define a constant global variable to handle it. <?php define(DOC_INCLUDES, $_SERVER['DOCUMENT_ROOT'] . "/includes"); require_once(DOC_INCLUDES . "/database.inc"); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2007 Share Posted March 7, 2007 Using my method you would only need to call.... <?php require_once 'database.inc'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.