...

View Full Version : Include Script



britishrallying
03-20-2004, 04:26 PM
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 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
$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!:)

Nightfire
03-20-2004, 04:29 PM
../ goes down a directory
/ is from root
./ from current directory

so you need to use


include("../php/images.php");

britishrallying
03-20-2004, 04:59 PM
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!:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum