让php自动检测当前目录

时间:2015-06-26 20:27:23

标签: php nginx directory


在localhost上我通常会这样做

file_put_contents('/script.zip', file_get_contents('http://example.com/script.zip'));

但似乎在我的vps上,php文件并没有得到“检测不到”的信息。目前的 目录。所以我必须得到document_root并手动设置路径。

$root = $_SERVER['DOCUMENT_ROOT'];
file_put_contents($root.'/script.zip', file_get_contents('http://example.com/thescript.zip'));

我确定必须有办法将nginx或php配置为自动
检测当前目录,但我似乎无法找到如何做到这一点。也许
我不知道如何搜索这个特定问题。

1 个答案:

答案 0 :(得分:0)

如果您希望在当前目录中创建文件,请使用“。”如下:

file_put_contents('./script.zip', file_get_contents('http://example.com/script.zip'));

'。'将指向运行php脚本的当前目录。

相关问题