Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include_once points to an other directory

Status
Not open for further replies.

solo1234

Programmer
Jun 25, 2007
39
NL
Hello PHP users,

In my script I am using the next script:

include_once('a.php');

The functions in a.php can't be called because 'a.php' is located in an other directory.

I tried:
include_once('../pages/a.php');
include_once('..//pages//a.php');
include_once('..\pages\a.php');
include_once('..\\pages\\a.php');
include_once('./pages/a.php');

But is was not possible to call the functions.
Can someone please give me the right syntax to call the php file from an other directory?

Nice regards,
Michelle.
 
the answer to your question depends on where the other directory is located. can you elucidate?
 
Hello jpadie,

Thanks for the reaction

Structure of the page:


Information of b.php
include_once('../a.php');
<function call to what is placed into a.php>

The functions from a.php can't be reached

When b.php is placed in the pages directory with:
include_once('a.php');
There is no problem.

Hopefully you can help me.
Michelle.
 
Since double dot (..) means parent directory, your script is in effect saying the following:
Code:
include_once ('[URL unfurl="true"]http://w.com/a.php');[/URL]
From your example it is obvious that a.php is not in the webroot but in another subdirectory called pages. So, changing it really reference the pages directory would be:
Code:
include_once('../pages/a.php');

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
i suspect you want

Code:
include_once '../[red]pages[/red]/a.php';

the '..' traverses the directory structure up one directory. since your files are in different sub directories you then need to traverse the structure down to the right directory before addressing the basename.

note that as include and require (and their _once variants) are language contructs rather than functions, the brackets are not required and are ignored if included (making them optional).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top