Re: include, relative path



^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
.



Relevant Pages

  • Re: require and do - absolute vs relative - let me try again
    ... > location using an absolute path. ... I have the same problem from command line. ... turns out it is just this script. ... with a relative path (any other relative path fails as well "No such file ...
    (comp.lang.perl.misc)
  • Re: include, relative path
    ... success, maybe because of the PHP version... ... This is a subdirectory for the root of the file system, ... directories which are located in the same relative path from the calling ...
    (alt.php)
  • Re: Getting the application path
    ... Use a relative path beginning with a tilde and a slash: ... the application's root, no matter what the domain name is. ... > Today, it is on a test server, but when I move it to the production ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Form Authentication
    ... interpret "~/" as application root. ... "slawek xxxxx" wrote in message ... > I have found a problem with form authentication method that I can't> solve. ... I have to set this path in> web.config and I want to use relative path. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Its trying to compile my JavaScript?
    ... I'm running from the ASP.NET web server, so the root of the application ... when use just "/" it's mean relative path from the root.. ... JavaScript. ...
    (microsoft.public.dotnet.framework.aspnet)