Jump to content

Dynamic path mapping


Sulman

Recommended Posts

Hi all,

 

Is there anything in PHP.ini that will allow me to dynamically alter paths?

 

e.g.:

<?php
include('/usr/webdata/site/includes/inc.php')
?>

php will then see that and rewrite it to 'mysite/includes/inc.php' then go off and get it.

 

Is this possible or am I barking up a non existent tree here?

 

Thanks

Link to comment
Share on other sites

Yeah, it is possible. You need to modify your include path

Altering the include path won't matter if you are using absolute paths.

 

To my knowledge there is no way to override that functionality. You could write your own function, maybe call it include2() and have that alter the path before doing the include.

Link to comment
Share on other sites

Hmmm thanks.

 

But I am trying to set up a mirror dev version of the site on my local machine. So changing the files is not an option.

 

It is going from unix to windows and there are alot of occasions where the full path on the server is used (/usr/webdata/mysite/includes/), but on my local windows machine that path will actually be 'C:\www\mysite\includes'

 

Any ideas how I may overcome this?

 

Thanks

Link to comment
Share on other sites

The only thing I can think of is to create the folder:

 

C:\usr\webdata\mysite\

 

and put the website in there. You will have to alter your apache config to point there instead though. That should work though because PHP on windows will interpret /usr/webdata/mysite/includes/ as C:\usr\webdata\mysite\includes\

 

But, your best solution is to fix your product and use relative paths. I would avoid $_SERVER['DOCUMENT_ROOT'] because you could technically have your website outside of Document Root and then point Apache to it with a ScriptAlias (which I use all the time).

Link to comment
Share on other sites

  • 3 months later...

???

I have a similar question, I wanted to dynamically access higher level paths..

Ex..

htdocs/mysite/myFirstScript 

points a links to 

htdocs/mysite/inc/myFunctionsScript 

that will need to write to myFirstScripts directory(not absolute) or a folder on the same level..

 

I have my script working so that it gets the target url, but having trouble with the logic..

and possibly the syntax. I'm thinking

 

using '../' to go up one directory and find the path from there, but is there an easier way?

I have been reading so many threads on the net arguing the meaning of each of following, much-less the best time to use each(on a *nix/apache host):

 

current: /public_html/

/somepath

./somepath

../somepath

 

I wish this was a part of - or I could find - the code/snippets. Please excuse me for piggy backing the thread, yet the problem was very similar to start a new thread. Any thoughts..

???

 

humblest thanks,

 

Nolo

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.