Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Include Script

  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Include Script

    Hi,

    I've run into a problem! How do you include a php script into files in other directorys?

    I must have had a memory blank, I use the following code on my main page and it works fine:
    PHP Code:
    <?php include "php/images.php"?>
    The code loads a script that displays images in the background of a table.

    But say i make a new page in a different directory such as http://www.britishrallying.com/feed/index.php, the above code wont work for that! it comes back with the following message:
    Warning: Failed opening 'php/images.php' for inclusion (include_path='.:/usr/share/pear') in /home/gareth1980/public_html/feed/index.php on line 50 >
    Ive tried putting a / before php but to no avail. Like i said my main page works fine: http://www.britishrallying.com/index.php , where am i going wrong?

    The code im trying to load is:
    PHP Code:
    <?php
    $dir
    =opendir("images/bg/color/");
    //This is the directory route to the folder
    $directory="/images/bg/color/";
    //This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on

    $pattern="\.(gif|jpg|jpeg|png|bmp|swf)$";
    if(!
    $dir)
    {
    die(
    "Failed to read directory");
    }
    $s=readdir($dir);
    $count="0";
    $image;
    while(
    $s)
    {
    if(
    ereg($pattern$s))
    {
    $image[$count]=$s;
    $count++;
    }
    $s=readdir($dir);
    }
    closedir($dir);

    //Spit it out
    $limit=count($image);
    $limit--;
    $randNum=rand(0,$limit);
    echo 
    "background=\"$directory$image[$randNum]\"";
    ?>
    Thanks in advance,

    Gareth
    ----------------------------------------
    I maybe thick but i get there in the end!

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    ../ goes down a directory
    / is from root
    ./ from current directory

    so you need to use
    PHP Code:
    include("../php/images.php"); 

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Erm, i feel a bit of a idiot!!!!

    Cheers Night fire

    Sometimes even the small things i forget! Doh

    Gareth
    ----------------------------------------
    I maybe thick but i get there in the end!


  •  

    Posting Permissions

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