including files - paths

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Berrow

    including files - paths

    If I'm working on a project, I'll usually create a folder to contain all
    the project files before uploading this to the root of the production
    server. The trouble is that if I do:
    include('/myfile.php')
    this looks at the root of local host, as it should and not at the root
    of the working directory. It means that if I want to use absolute
    links, I have to change them before I upload.

    Or am I missing something blindingly obvious?

    I'm pretty sure this has been done before (FAQ entry material?), but not
    for a while. :-)
    --
    Geoff Berrow 011000100110110 0010000000110
    001101101011011 001000110111101 100111001011
    100110001101101 111001011100111 010101101011
  • Hans van Kranenburg

    #2
    Re: including files - paths

    Geoff Berrow wrote:[color=blue]
    > If I'm working on a project, I'll usually create a folder to contain
    > all the project files before uploading this to the root of the
    > production server.[/color]
    [color=blue]
    > The trouble is that if I do:
    > include('/myfile.php') this looks at the root of local host, as it
    > should and not at the root of the working directory. It means that
    > if I want to use absolute links, I have to change them before I
    > upload.[/color]

    Change or extend your local configuration so that it reflects the
    configuration at the remote server.

    An easy way is creating a virtual host on your local box with a
    documentroot pointing to the wannabe /...
    [color=blue]
    > Or am I missing something blindingly obvious?[/color]
    No, I don't think so

    Hans

    --
    "He who asks a question is a fool for five minutes;
    he who does not ask a question remains a fool forever"

    Comment

    • Geoff Berrow

      #3
      Re: including files - paths

      I noticed that Message-ID: <4260189c$0$147 $e4fe514c@news. xs4all.nl> from
      Hans van Kranenburg contained the following:
      [color=blue]
      >Change or extend your local configuration so that it reflects the
      >configuratio n at the remote server.
      >
      >An easy way is creating a virtual host on your local box with a
      >documentroot pointing to the wannabe /...[/color]

      Any idea where I might find instructions on how to do that?

      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: including files - paths

        Geoff Berrow wrote:[color=blue]
        > If I'm working on a project, I'll usually create a folder to contain[/color]
        all[color=blue]
        > the project files before uploading this to the root of the production
        > server. The trouble is that if I do:
        > include('/myfile.php')
        > this looks at the root of local host, as it should and not at the[/color]
        root[color=blue]
        > of the working directory. It means that if I want to use absolute
        > links, I have to change them before I upload.[/color]

        The quick solution is to use relative path (something like
        .../foo.php or ./foo.php). But, if we use relative path for all
        includes, it will hit performance. So, I use something like:

        <?php
        //config.inc.php
        $CFG['project_path'] = '/home/foo/foo/';
        //etc etc
        ?>

        <?php
        //foo.php
        require_once('. ./common/config.inc.php' ); //relative to project
        require_once($C FG['project_path'] . 'html/header.html'); //absolute
        //etc etc...
        require_once($C FG['project_path'] . 'html/footer.html'); //absolute
        ?>

        As seen, only one path is relative. I even have a mechanism to auto
        detect the project path in config.inc.php.
        [color=blue]
        > I'm pretty sure this has been done before (FAQ entry material?), but[/color]
        not[color=blue]
        > for a while. :-)[/color]

        Yes, this has to be included in FAQ. But, what could be an
        appropriate question?

        --
        <?php echo 'Just another PHP saint'; ?>
        Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

        Comment

        Working...