开发者

How to set current working directory in PHP to the script executed directory?

开发者 https://www.devze.com 2023-03-13 04:21 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号