PHP Relative Include with Virtual Directory on IIS7
I have a root configuration virtual directory (named "config" pointing to a directory inside /wwwroot/) specified in IIS7. I want to access this virtual dir programmatically via an "include" function such as:
include '/config/main.php';
I get Warning: require(config/开发者_开发问答main.php) [function.require]: failed to open stream
errors. I have tried the following:
/config/
, \config\
, ./config/
, config/
, ~/config/
, $SERVER_['DOCUMENT_ROOT']/config/
To no avail. Why does PHP have to be such a dink about site relative references!? Not to rain on the parade, but ASP can handle site relative references (or document relative with ../blah.php
) with ease!
Any ideas? I have looked at the set_include_path function and I'm going to try that out in the meantime, but it basically seems like that would be hard-coding my directory paths - annoying for moving code from dev to prod environments.
Try it:
dirname(__FILE__).'\\config\\main.php';
Issue is sort of closed because I couldn't find a satisfactory answer, I simply just rejigged my problem so that there's no virtual directories. Damn PHP and relative paths! It seems to be a problem specifically with IIS.
If anyone finds a better solution the problem I will be more than happy to switch the selected answer.
精彩评论