获取symlink'd php脚本的当前目录,而不是实际的php脚本 [英] get current directory of symlink'd php script and not actual php script

查看:144
本文介绍了获取symlink'd php脚本的当前目录,而不是实际的php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从一个文件夹符号链接到另一个文件的脚本

I have a script that is symlinked from one folder to another

/var/www/default/index.php

符号链接到

/var/www/mysite/index.php

但是当我打电话 DIR 从mysite路径解析到默认的起始路径。如何使它返回mysite路径(符号链接文件夹,而不是实际文件夹)

However when i call DIR from mysite the path resolves to the origial path under default. How do i make it return the mysite path (the symlinked folder, not the actual folder)

推荐答案

对于Web服务器请求

dirname($ _ SERVER ['SCRIPT_FILENAME'])会给你所需要的。没有$ _SERVER ['PHP_SELF']甚至REQUEST_URI将会有。

dirname($_SERVER['SCRIPT_FILENAME']) will give you what you need. Failing that $_SERVER['PHP_SELF'] or even REQUEST_URI will have it.

对于CLI(命令行)

这不会在cli(命令行)脚本中工作,因为$ _SERVER是由网络服务器添加的。

this won't work in cli (command line) scripts as $_SERVER is added by the web server.

幸运的是很多更容易使用cli脚本(因为没有Web服务器可以弄乱事物)。

Fortunately it's a lot easier with cli scripts (as there is no web server to mess about with things).

您需要的是阅读启动脚本的命令行: http://php.net/manual/en/reserved.variables.argv.php 。第一个参数$ argv [0]始终是用于运行脚本的名称。

All you need is to read the command line that started the script: http://php.net/manual/en/reserved.variables.argv.php. The first argument $argv[0] is always the name that was used to run the script.

这篇关于获取symlink'd php脚本的当前目录,而不是实际的php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆