How to set current working directory in PHP to the script executed directory?
I have a website on iis7 with php.
When i call getcwd()
it returns base directory whith php-cgi.exe
. But I whant cwd automaticly change to current ex开发者_运维技巧ecuted script directory.
How can i configure it via php.ini or iis or else?
I think you just need to chdir() in your script:
chdir(__DIR__);
Or, before PHP 5.3:
chdir(dirname(__FILE__));
To the currently executed script directory: chdir(dirname($_SERVER['SCRIPT_FILENAME']));
To the currently executed file directory: chdir(dirname(__FILE__));
There is a slight difference between them. Script directory is always the directory of the main script file being executed, while the file directory can also be the directory of the included php script file.
精彩评论