Re: include, relative path
- From: "J.O. Aho" <user@xxxxxxxxxxx>
- Date: Wed, 30 Apr 2008 20:00:52 +0200
^AndreA^ wrote:
Hi everybody,
I'm having a stupid problem with the include command.
I looked around and I found some solutions but, I don't know why, they
don't work at all.
Briefly, this is the structure of my website:
mysite/libraries/db_details.php
mysite/registration/check.php
I need to connect to the database from the script "check.php", and the
details of the database are in "db_details.php", of course... ;-)
so, I have to include "db_details.php" from "check.php" script...
I'm under linux and I've tried so many different solutions without
success, maybe because of the PHP version (5.2.3)... and some
solutions I found were a bit old (2002, 2003) and so I thougth they
could not to work any more.
Here some of them,
Your man problem is that you don't understand how paths works in a Unix-like environment. It will always be easier to give full paths instead, but this causes problems if you would move your scripts.
/libraries
This is a subdirectory for the root of the file system, with other words almost equal to "Libraries:\" from the weird microsoft world.
mysite/libraries/
This case you are looking at a directory which is inside your current directory, so if you aren't in /, you will of course not find it.
ini_set("include_path",".:/libraries");
include('/..//libraries/db_details.php');Here you tell to go to root, then get one step closer to root (which still is root) and then look for the libraries directory, we could translate this to "Libraries:\".
include("../registration/db_details.php");This time you back one step from your current directory and from the parent directory you go into the registration directory and pick the db_details.php file.
include "db_details.php";This includes a file in your current directory.
If you are accessing www.yoursite.com/registration/check.php
then for a relative path include you would use
include "../libraries/db_details.php";
If you then include another file from db_details.php, you have to give the path relative to check.php, or use full paths.
Keep in mind when you use relative paths, is always relative to the file you load in the web browse, not to the file itself. One way to get around some troubles are to use symlinks, this way you can have virtual directories which are located in the same relative path from the calling file, but that could be a bit difficult before you have a grasp of how paths works.
--
//Aho
.
- References:
- include, relative path
- From: ^AndreA^
- include, relative path
- Prev by Date: Re: Full Range ?
- Previous by thread: Re: include, relative path
- Index(es):
Relevant Pages
|