directory paths...how does this work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John K

    directory paths...how does this work?

    In ASP/IIS if I want to point to a folder/directory in the root as an
    in include I write this...

    <!--#include virtual="/menu.asp" -->

    In PHP/Apache I have to do this...
    <?php include "menu.php" ?> or something like this....

    My problem is in asp I can reference this file from any
    folder/directory. For example, if I were here.... "/admin/default.asp"
    I could reference the include as is. In php I can't do this, at least
    I don't know how to. Another problem is that if there are file paths
    in the include itself this problem comes up again. I know I could
    write this <?php include "../menu.php"?> and it would find it's way to
    the file but what about the file paths in the include? This is a menu
    with relative paths to images.

    How can I point at a file in the root from any directory in my website
    using a relative path? I know I should probably avoid an http://
    reference.

    Thanks!!

  • Tim Van Wassenhove

    #2
    Re: directory paths...how does this work?

    On 2006-01-06, John K <kinane3@yahoo. com> wrote:[color=blue]
    > My problem is in asp I can reference this file from any
    > folder/directory. For example, if I were here.... "/admin/default.asp"
    > I could reference the include as is. In php I can't do this, at least
    > I don't know how to. Another problem is that if there are file paths
    > in the include itself this problem comes up again. I know I could
    > write this <?php include "../menu.php"?> and it would find it's way to
    > the file but what about the file paths in the include? This is a menu
    > with relative paths to images.[/color]

    PHP has a configuration setting include_path.
    Apart from setting it in php.ini you can also change it at runtime
    (http://www.php.net/ini_set).
    And you can manipulate it with http://www.php.net/get_include_path and


    The only problem you might experience is that paths are separated with ; on
    windows platforms and with : on unix platforms. To avoid this i suggest you take
    an approach as following:

    $include_paths = array('.', '..', '/var/somewhere' , get_include_pat h());
    ini_set('includ e_path', implode(PATH_SE PARATOR, $include_paths) );


    --
    Met vriendelijke groeten,
    Tim Van Wassenhove <http://timvw.madoka.be >

    Comment

    • Jerry Stuckle

      #3
      Re: directory paths...how does this work?

      John K wrote:[color=blue]
      > In ASP/IIS if I want to point to a folder/directory in the root as an
      > in include I write this...
      >
      > <!--#include virtual="/menu.asp" -->
      >
      > In PHP/Apache I have to do this...
      > <?php include "menu.php" ?> or something like this....
      >
      > My problem is in asp I can reference this file from any
      > folder/directory. For example, if I were here.... "/admin/default.asp"
      > I could reference the include as is. In php I can't do this, at least
      > I don't know how to. Another problem is that if there are file paths
      > in the include itself this problem comes up again. I know I could
      > write this <?php include "../menu.php"?> and it would find it's way to
      > the file but what about the file paths in the include? This is a menu
      > with relative paths to images.
      >
      > How can I point at a file in the root from any directory in my website
      > using a relative path? I know I should probably avoid an http://
      > reference.
      >
      > Thanks!!
      >[/color]

      Check out $_SERVER['DOCUMENT_ROOT']. It always points to the root
      directory of your web site, no matter where that is.

      You could, for instance, do something like:

      <?php include($_SERVE R['DOCUMENT_ROOT'] . '/include/menu.php'); ?>

      or similar.


      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • John K

        #4
        Re: directory paths...how does this work?

        As it's turning out this entire problem "isn't" a problem on the live
        server. I'm using XAMPP to develop locally and it appears this problem
        is coming from there? I haven't throughly tested on the live server
        yet but someone demonstrated to me that the absolute paths "do" work
        there, they just don't on XAMPP. It may yet turn out to no be this
        simple but we'll see.

        Are there any XAMPP experts out there?

        Comment

        Working...