Page 1 of 1

Include and evaluate another php file relatively

Posted: Fri Aug 12, 2005 11:03 pm
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

Posted: Fri Aug 12, 2005 11:31 pm
by feyd
if you wrote this functionality into a function, you'd be able to list the files in which ever directories you wish.

Posted: Fri Aug 12, 2005 11:38 pm
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.

Posted: Sat Aug 13, 2005 12:32 am
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.

Posted: Sat Aug 13, 2005 12:38 am
by BMN
I am an extreme newbie...how would I put it in a classs etc?

Posted: Sat Aug 13, 2005 12:41 am
by feyd
it may be best to simply place the various parts and components into functions.

Posted: Sat Aug 13, 2005 1:44 am
by BMN
How?
Like I said...extreme newbie

Posted: Sat Aug 13, 2005 8:51 am
by feyd