PHP 显示当前服务器路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12251054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:08:47  来源:igfitidea点击:

PHP display current server path

php

提问by Satch3000

I need to setup a path in my php but I currently don't know the path.

我需要在我的 php 中设置一个路径,但我目前不知道该路径。

I need to configure the paths the the uploads directory

我需要配置上传目录的路径

Should look like this below:

应该如下所示:

/srv/www/uploads/

My uploads.php file is in the root...so

我的uploads.php 文件在根目录中......所以

www/uploads/ ???

Is there anyway that I could get php to tell me my current path?

无论如何,我可以让 php 告诉我我当前的路径吗?

回答by Nick

If you call getcwdit should give you the path:

如果你调用getcwd它应该给你路径:

<?php
  echo getcwd();
?>

回答by Eusebius

  • To get your current working directory: getcwd()(documentation)
  • To get the document root directory: $_SERVER['DOCUMENT_ROOT']
  • To get the filename of the current script: $_SERVER['SCRIPT_FILENAME']
  • 为了让您的当前工作目录:getcwd()文档
  • 获取文档根目录: $_SERVER['DOCUMENT_ROOT']
  • 获取当前脚本的文件名: $_SERVER['SCRIPT_FILENAME']

回答by Gregory R.

echo $_SERVER["DOCUMENT_ROOT"];

'DOCUMENT_ROOT' The document root directory under which the current script is executing, as defined in the server's configuration file.

'DOCUMENT_ROOT' 当前脚本在其下执行的文档根目录,如服务器配置文件中所定义。

http://php.net/manual/en/reserved.variables.server.php

http://php.net/manual/en/reserved.variables.server.php

回答by David

You can also use the following alternative realpath.

您还可以使用以下替代realpath

Create a filecalled path.php

创建一个名为path.php的文件

Put the following codeinside by specifying the name of the created file.

通过指定创建的文件的名称将以下代码放入其中

<?php 
    echo realpath('path.php'); 
?>

A php file that you can move to all your folders to always have the absolute path from where the executed file is located.

一个可以移动到所有文件夹的 php 文件,以始终具有执行文件所在位置的绝对路径。

;-)

;-)

回答by Johnzo

php can call command line operations so

php 可以调用命令行操作,所以

echo exec("pwd");