CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2005
    Posts
    36

    how to specify the root directory of the web site?

    <?php require("include/const.php"); ?>

    In the quotation marks.
    "/" can't be used.
    I want to include the file in "http://mywebsite/include/", but I don't want to specify the website name.

  2. #2
    Join Date
    May 2004
    Location
    Pell City, Alabama
    Posts
    126

    Re: how to specify the root directory of the web site?

    <?php require("../include/const.php"); ?>


    should do the trick

  3. #3
    Join Date
    May 2005
    Posts
    36

    Exclamation Re: how to specify the root directory of the web site?


    I know how to use "../",
    but can I specify the root directory simply?
    Because some PHP files may be moved.
    If so, I'd have to modify each file.

  4. #4
    Join Date
    May 2004
    Location
    Germany
    Posts
    655

    Re: how to specify the root directory of the web site?

    you have to specify the path on your server to the include file with phps include directive.

    so if your include file lies at /usr/local/apache/htdocs/include/functions.inc

    then you can do a include( '/usr/local/apache/htdocs/include/functions.inc' );
    there are 10 kinds of people. those who understand binary and those who don't...

    rate a post if you find it usefull, thx
    check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/

  5. #5
    Join Date
    Sep 2005
    Posts
    2

    Re: how to specify the root directory of the web site?

    Quote Originally Posted by bigBA
    you have to specify the path on your server to the include file with phps include directive.

    so if your include file lies at /usr/local/apache/htdocs/include/functions.inc

    then you can do a include( '/usr/local/apache/htdocs/include/functions.inc' );
    using a full path like that isn't ver "portable", it won't work well on some other systems, try something like this:

    include(dirname(__FILE__)."/includes/const.php");

    That would make it so that wherever your file is, it will always look for the /includes/const.php file

    hope it helps,
    camowel

  6. #6
    Join Date
    May 2004
    Location
    Germany
    Posts
    655

    Re: how to specify the root directory of the web site?

    well (IMHO), this should have the same effect like include('includes/const.php'), means that includes is a subdirectory of the directory where the files is in which this include statement lies.

    but the op says:
    Because some PHP files may be moved.
    so, when he moves the file with you include, he also has to move the includes sub dir....

    but you are right, this isn't very portable - but if you have to move you php files from one machine to another... which aren't equally configured, you have a lot of work to do, maybe modifying each page, too... so changing those includes wouldn't count
    there are 10 kinds of people. those who understand binary and those who don't...

    rate a post if you find it usefull, thx
    check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/

  7. #7
    Join Date
    Sep 2005
    Posts
    1

    Re: how to specify the root directory of the web site?

    Quote Originally Posted by _mynameisno1
    <?php require("include/const.php"); ?>

    In the quotation marks.
    "/" can't be used.
    I want to include the file in "http://mywebsite/include/", but I don't want to specify the website name.
    When faced with a similar issue, what I did was to use this:

    <?php include "start.php" ?>

    and then I put a little file (mine are only 1 line each) called start.php in each directory with info specific to that directory, as in WHAT directory it is.

    Once you have that, you can define (in start.php) a constant to hold the current directory and the base directory and then use that to include your files.

    Were you to port the system, only the start.php files would need editing.

    Hershel

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured