Path help please!

I’m getting this error:

require_once() [function.require]: Failed opening required ‘Archive/Tar.php’ (include_path=‘.:/usr/local/php5/lib/php’)

I’m on a shared server and ‘Archive/Tar.php’ is at

/home/user/php/Archive/Tar.php

What would the correct include_path be? :inspector:

What directory are you including the file from? Also, can you post the require statement so that we can see where you’re going wrong?

I’m on shared LAMP server.

PEAR is installed at

/home/user/php/Archive/
/home/user/php/PEAR/
/home/user/php/PEAR.php

The file calling the Archive/Tar.php script is at

/home/user/includes/classes/Archive.php

The require statement is

require_once 'Archive/Tar.php';

This works:

set_include_path ('/home/user/php');
require_once 'Archive/Tar.php';
restore_include_path();

My question is how is that “include_path” set in the “.:/usr/etc./etc./etc.” format?

In other words, what do I use for an “include_path” instead of

'.:/usr/local/php5/lib/php'

Edit **
Woops, I misread your post.

I think in this case, a relative path such as Archive/Tar.php will be assumed that Archive is in the PEAR installation directory. Anytime I run PHP from a command line I always use absolute pathing.

I guess my question comes down to "What does the /usr/ in the include path mean? How does it relate to the file path (/home/user/the/rest/of/the/path) ?

Using a relative path, can you tell me if the following works?


require '../../php/Archive/Tar.php';

It looks like we need to go up two directories (from classes to user), and then traverse along the php and Archive directories.

I would suggest, however, that you use an absolute path because no resolving has to be done (making them quicker). For this, we can use the $_SERVER[‘DOCUMENT_ROOT’] variable, and then add on the relative path to the file from there. I’m not sure what you have your DOCUMENT_ROOT directive defined as, but if you echo it out, then your can just add on the necessary directories to it:


require $_SERVER['DOCUMENT_ROOT'].'/path/to/file.php';

This works (3 back, not 2)

    require_once '../../../php/Archive/Tar.php';

This works

    set_include_path ('../../../php');
    require_once 'Archive/Tar.php';

This does not work

    require $_SERVER['DOCUMENT_ROOT'].'/path/to/file.php';

The script happens to be in a subdomain and $_SERVER[‘DOCUMENT_ROOT’] returns

/home/user/public_html/subdomain

which is in the public directory, not the root. In the main domain it would return

/home/user/public_html

not too reliable.

Much neglected FILE, on the other hand, returns

/home/user/includes/classes/Archive.php

which is better but still no help.

I’m sticking with absolute path


    set_include_path ('/home/user/php');
    require_once 'Archive/Tar.php';
    restore_include_path();

Thanks all!

EDIT - This also works:

$path = $_SERVER['DOCUMENT_ROOT'];
$pos = strpos($path, 'public_html');
$path = substr($path, 0, $pos).'php';
set_include_path ($path);
require_once 'Archive/Tar.php';
restore_include_path();