SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question 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?
    Denny Schlesinger
    web services

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    125
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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?

  3. #3
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm on shared LAMP server.

    PEAR is installed at
    Code:
    /home/user/php/Archive/
    /home/user/php/PEAR/
    /home/user/php/PEAR.php
    The file calling the Archive/Tar.php script is at
    Code:
    /home/user/includes/classes/Archive.php
    The require statement is
    PHP Code:
    require_once 'Archive/Tar.php'
    This works:
    PHP Code:
    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
    Code:
    '.:/usr/local/php5/lib/php'
    Denny Schlesinger
    web services

  4. #4
    SitePoint Zealot wh33t's Avatar
    Join Date
    Aug 2011
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by captainccs View Post
    I'm on shared LAMP server.

    PEAR is installed at
    Code:
    /home/user/php/Archive/
    /home/user/php/PEAR/
    /home/user/php/PEAR.php
    The file calling the Archive/Tar.php script is at
    Code:
    /home/user/includes/classes/Archive.php
    The require statement is
    PHP Code:
    require_once 'Archive/Tar.php'
    This works:
    PHP Code:
    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
    Code:
    '.:/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.

  5. #5
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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) ?
    Denny Schlesinger
    web services

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    125
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by captainccs View Post
    I'm on a shared server and 'Archive/Tar.php' is at

    /home/user/php/Archive/Tar.php
    Quote Originally Posted by captainccs View Post
    The file calling the Archive/Tar.php script is at
    Code:
    /home/user/includes/classes/Archive.php
    Using a relative path, can you tell me if the following works?

    PHP Code:
    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:
    PHP Code:
    require $_SERVER['DOCUMENT_ROOT'].'/path/to/file.php'

  7. #7
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This works (3 back, not 2)
    PHP Code:
        require_once '../../../php/Archive/Tar.php'
    This works
    PHP Code:
        set_include_path ('../../../php');
        require_once 
    'Archive/Tar.php'
    This does not work
    PHP Code:
        require $_SERVER['DOCUMENT_ROOT'].'/path/to/file.php'
    The script happens to be in a subdomain and $_SERVER['DOCUMENT_ROOT'] returns
    Code:
    /home/user/public_html/subdomain
    which is in the public directory, not the root. In the main domain it would return
    Code:
    /home/user/public_html
    not too reliable.

    Much neglected __FILE__, on the other hand, returns
    Code:
    /home/user/includes/classes/Archive.php
    which is better but still no help.

    I'm sticking with absolute path
    PHP Code:
        set_include_path ('/home/user/php');
        require_once 
    'Archive/Tar.php';
        
    restore_include_path(); 
    Thanks all!

    EDIT - This also works:
    PHP Code:
    $path $_SERVER['DOCUMENT_ROOT'];
    $pos strpos($path'public_html');
    $path substr($path0$pos).'php';
    set_include_path ($path);
    require_once 
    'Archive/Tar.php';
    restore_include_path(); 
    Last edited by captainccs; Feb 22, 2013 at 10:18. Reason: Found the solution!
    Denny Schlesinger
    web services


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •