Php include help

Discussion in 'PHP' started by hexadesigns, Sep 27, 2009.

  1. #1
    This works:

    
    <?php $thispath = "/home/user/somedomain.com/public_html/somefolder/" ?>
    <?php include $thispath.'navigation.php'; ?>
    
    PHP:
    This does not:
    
     <?php include '/somefolder/navigation.php'; ?>
    
    PHP:
    Is there a workaround?
     
    Last edited: Sep 27, 2009
    hexadesigns, Sep 27, 2009 IP
  2. rldowling03

    rldowling03 Notable Member

    Messages:
    1,763
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    200
    #2
    Use:

    <?php include 'somefolder/navigation.php'; ?>
    PHP:
    Because your using /somefolder/navigation.php it is tryignt o include the root linux folder somefolder, so remove the first / to use somefolder in the scripts directory
     
    rldowling03, Sep 27, 2009 IP
  3. hexadesigns

    hexadesigns Peon

    Messages:
    350
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What if the script is called from

    someotherfolder/subfolder/script.php

    will the
    <?php include 'somefolder/navigation.php'; ?>
    PHP:
    work?

    The directory structure is

    public_html/somefolder


    public_html/somefolder/navigation.php


    public_html/someotherfolder/subfolder


    public_html/someotherfolder/subfolder/script.php
     
    hexadesigns, Sep 27, 2009 IP
  4. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #4
    <?php include './somefolder/navigation.php'; ?>

    that would work too
     
    Bohra, Sep 28, 2009 IP
  5. sunchiqua

    sunchiqua Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?php include '../navigation.php'; ?>
    PHP:
    [B].[/B] - current directory
    [B]..[/B] - previous directory
    [B]/somepath[/B] - assumes that somepath is in the root folder
    [B]somepath/[/B] - assumes that somepath is in the current directory
    Code (markup):
     
    sunchiqua, Sep 28, 2009 IP
  6. hexadesigns

    hexadesigns Peon

    Messages:
    350
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I just decided to use

    
    <?php include $_SERVER[DOCUMENT_ROOT].'/somefolder/navigation.php'; ?>
    
    PHP:
    and it works fine.

    Thanks everyone!
     
    hexadesigns, Sep 28, 2009 IP