Sulman Posted February 29, 2008 Share Posted February 29, 2008 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 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted February 29, 2008 Share Posted February 29, 2008 Yeah, it is possible. You need to modify your include path Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 29, 2008 Share Posted February 29, 2008 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. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted February 29, 2008 Share Posted February 29, 2008 Yeah, sorry, i meant to point that out. I meant to say that it might be an option to use relative links instead. Quote Link to comment Share on other sites More sharing options...
Sulman Posted February 29, 2008 Author Share Posted February 29, 2008 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 29, 2008 Share Posted February 29, 2008 You should be using $_SERVER['DOCUMENT_ROOT'] to form your absolute server paths. Quote Link to comment Share on other sites More sharing options...
Sulman Posted February 29, 2008 Author Share Posted February 29, 2008 You're right...but this is existing code from before my time...so I'm afraid I'm stuck with the hand coded path. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 29, 2008 Share Posted February 29, 2008 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). Quote Link to comment Share on other sites More sharing options...
Sulman Posted February 29, 2008 Author Share Posted February 29, 2008 Hmmm, Ok, thanks for your replies. Think I might have to have a rethink and sort the paths out properly. Thanks all! Quote Link to comment Share on other sites More sharing options...
nolochemical Posted June 24, 2008 Share Posted June 24, 2008 ??? 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.