Include and evaluate another php file relatively

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BMN
Forum Newbie
Posts: 15
Joined: Fri Aug 12, 2005 10:54 pm

Include and evaluate another php file relatively

Post by BMN »

I have a php file, for example that has an image in it. I want to include this file within another page (in another directory etc), but include it as if it were within that directory. include( evaluates it in its own context, then prints the results. This is not what I want. Can anyone help?

I realise this is not very well explained, so i will illustrate an example:

fileA.php is in a dir called dirA/
This file basically gives a directory lisiting of the current dir.

fileB.php is in a dir calle dirB/
I want this file to include fileA.php, but instead of listing the contents of dirA/ (as it does at the moment), I want it to list the contents of dirB/ (the dir where fileB.php is calling it from.

at the moment I'm just using include()

Thanks,
Mitch
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you wrote this functionality into a function, you'd be able to list the files in which ever directories you wish.
BMN
Forum Newbie
Posts: 15
Joined: Fri Aug 12, 2005 10:54 pm

Post by BMN »

The file I want to include is a lot more complicated that just a plain dir listing. The reason I want to do this, is that I have the file sitting in about a hundred directories, and everytime I update the file, I have to go and copy it into all the other directories. This is very annoying, and I thought it would be easier to have those hundred file linking to just one main file, so when i updated it, there were all up to date.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if coded correctly, you may be able to use a symlink.. but I'd personally recode the file such that all the functionality is contained in one or more functions (probably classes too) so I can use the functionality anywhere I choose, in any fashion I choose it.
BMN
Forum Newbie
Posts: 15
Joined: Fri Aug 12, 2005 10:54 pm

Post by BMN »

I am an extreme newbie...how would I put it in a classs etc?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it may be best to simply place the various parts and components into functions.
BMN
Forum Newbie
Posts: 15
Joined: Fri Aug 12, 2005 10:54 pm

Post by BMN »

How?
Like I said...extreme newbie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post Reply