Closed Thread Icon

Topic awaiting preservation: including a script but running it in another dir Pages that link to <a href="https://ozoneasylum.com/backlink?for=12169" title="Pages that link to Topic awaiting preservation: including a script but running it in another dir" rel="nofollow" >Topic awaiting preservation: including a script but running it in another dir\

 
Author Thread
butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 04-09-2002 21:43

I could swear I asked you guys something similar to this before, but couldn't find the thread.

I want to include a php page from one directory in a page that resides in another directory. Problem is, the included page runs as if it's in the directory of the calling page, which ruins my script because it uses getcwd() to make the proper paths. Because it is executing like it is in the directory of the page that called it, getcwd() returns the calling directory, not the directory the script is in.

Sorry if I'm explaining too much, or badly.

How do I make a script execute in the directory it's in and then return the output to the calling page?

Thanks all.

-Butcher-

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 04-09-2002 23:56

PHP treats includes as if they were initally part of the script that is currently running.

Although if your including that script then you at least know the relative path from cwd to it so you could just add that to what cmd returns. Yet I think it'd be easier just to write a function that handled the problem for you.

Just remember, if you want to act on any directory outside of the directory that the base script is running in then you'll always need to hand your functions the path to it. Including a file won't change the cwd as the included file is not run as a seperate script.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 04-10-2002 15:19

Butcher, replace all calls to getcwd() function (in included files) with dirname(__FILE__) and everything will be fine...


Dark Phoenix
Paranoid (IV) Inmate

From: Harrow, Ontario, Canada
Insane since: Feb 2002

posted posted 04-10-2002 16:19

I think there may be a way of doing that using exec(), but I severly advise against that; exec() is the Devil of PHP functions and should only be used if nothing else will ever work.

"No one's going to give you a map; you've got to walk your own path." - Hot Ice Hilda, Outlaw Star.

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 04-11-2002 03:21

Thanks mr.maX

It worked nicely! I had to make some adjustments to some of the other paths in the script to make it go, but go it does!


Thanks Dracusis and Dark Phoenix, I appreciate you guys taking the time.


-Butcher-

« BackwardsOnwards »

Show Forum Drop Down Menu