问题描述
我正在将我的网站从一台服务器转移到另一台服务器.我有一些使用is_read函数的php脚本,该函数使用当前的工作目录.
I'm in the process of transferring my website from one server to another. I have some php scripts that use the is_readable function which uses the current working directory.
在旧服务器上,当我调用getcwd()时,它将输出在其中执行脚本的文件夹.在新服务器上,它输出根目录"/".
On the old server, when I call getcwd(), it outputs the folder in which the script is being executed. On the new server it outputs the root directory '/'.
我想知道如何配置PHP以使用当前文件夹而不是'/'. 我不想更改任何在旧服务器上已经可以运行的PHP代码.我可以配置新服务器,但不知道要更改哪些设置.如果有帮助,我正在使用apache2.
I would like to know how I can configure PHP to use the current folder instead of '/'. I don't want to have to change any PHP code that already works on the old server. I can configure the new server, but don't know what settings to change. I'm using apache2, if that helps.
好像我的工作目录不是我想的那样是root.当我创建一个testFile.php并回显getcwd()时,它显示php文件所在的目录.但是在我的问题文件中,同一目录中的getcwd()显示为'/'
It seems as though my working directory is not root like I thought. When I create a testFile.php and echo getcwd() it shows the directory the php file is in. But in my problem file, in the same directory, getcwd() shows up as '/'
推荐答案
chdir(__DIR__);
或
chdir(dirname(__FILE__));
但这应该是默认设置.
这篇关于PHP:如何将当前工作目录设置为与执行脚本的目录相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!