SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: How do you?

  1. #1
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you?

    Apologies if this is covered elsewhere - I have had a good hunt but couldn't find anything. Could seriosuly use some advice from those who know please?

    I'm building a site with multiple sub folders of pages, using includes commands - how do you code the include command so as to avoid having to upload each include file to each seperate local folder?

    I've tried
    <?php include("/includes-files/logo.txt"); ?>
    <?php include("http://www.sitename.com/includes-files/logo.txt"); ?> but to make the include .txt file show at all I have to upload the required .txt files to every single folder and sub folder.

    Am I being terribly dim (more than likely ) but there must be a way to upload one set of include files to root and have them called however much you drill down into sub folders, surely. Otherwise, I'm in for a heck of an update stretch each time I need to change an include!

    Regards

    Rufus

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    include() works with the filesystem, so a URL won't work. Just using ./includes-files/logo.txt might work, otherwise you might need to use something like this:
    PHP Code:
    include $_SERVER['DOCUMENT_ROOT'] . '/includes-files/logo.txt' 

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your include files include other files, you may need to set a configuration parameter to indicate your include file path. If you don't have access to the php.ini file, you can do it in your PHP code:
    PHP Code:
    ini_set('include_path'$_SERVER['DOCUMENT_ROOT'] . '/include-files/'); 
    Last edited by AutisticCuckoo; Apr 27, 2007 at 04:34. Reason: Error corrected
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Raffles,

    Many thanks for the reply and advice.

    I shall give that a try.

    Can I just check please (make sure i get it right in other words) that what I should put into the code would be

    <?php include(include $_SERVER['DOCUMENT_ROOT'] . '/includes-files/logo.txt'); ?>



    Tommy - thank you for your advice. I'm not yet at the level of ability to think of including includes within includes but I shall store that away for the day when I do get that far!

    With thanks

    Rufus

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, that's wrong, you have two includes there. It should be:
    PHP Code:
    <?php include($_SERVER['DOCUMENT_ROOT'] . '/includes-files/logo.txt'); ?>
    But I would try the first thing I posted first:
    PHP Code:
    <?php include('./includes-files/logo.txt'); ?>
    Then if that doesn't work use the DOCUMENT_ROOT version.

    I might be wrong, but I think what Tommy posted should be
    PHP Code:
    ini_set('include_path'$_SERVER['DOCUMENT_ROOT'] . '/include-files/'); 
    ?

    http://uk.php.net/manual/en/ini.core...i.include-path

  6. #6
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the advice Raffles - much appreciated.

    I shall give it a try and report back.

    Regards

    Rufus

  7. #7
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in all likelihood, you are simply not pointing to the file correctly. The method of including a file is not unlike a relative link in a standard html link.

    If your file is in /web-design/about.htm and you want to jump up to the parent folder and contact, you use <a href="../contact.htm">contact</a>. The same principle applies for including a php file, OR, you can use the absolute server path, which $_SERVER['DOCUMENT_ROOT']; will show when echoed.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    I might be wrong, but I think what Tommy posted should be
    You're absolutely right. I've updated my previous post.

    PHP Code:
    for ($i 0$i 100; ++$i) {
        echo 
    "I will not post without checking the documentation again!\n";

    Birnam wood is come to Dunsinane


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
  •