在PHP中创建绝对路径的最佳方法? (请参阅内部列出的3种方法) [英] Best method for creating absolute path in PHP? (See 3 methods listed inside)

查看:102
本文介绍了在PHP中创建绝对路径的最佳方法? (请参阅内部列出的3种方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以毫无问题地创建路径,但是我想知道这3种方法中哪一种最可靠,最可靠,并且可以在大多数服务器上使用.

I can create paths with no problem, but I want to know which of these 3 methods is the most rock solid and reliable and will work on the most servers.

现在,我在脚本中使用方法1,并且某些用户遇到路径问题.我只想要可以在任何版本的php和几乎所有服务器配置上使用的方法.

Right now I am using method 1 in my script and some users are having path issues. I just want the method that will work on any version of php and almost any server config.

1.  <?php echo $_SERVER['DOCUMENT_ROOT']; ?>

2.  <?php echo getcwd(); ?>

3.  <?php echo dirname(__FILE__); ?>

非常感谢您可以为此提供的任何专业知识!

Thank you so much for any expertise you can provide about this!

推荐答案

dirname(__FILE__)将始终起作用,而不考虑平台或Web服务器.在服务器配置之间,DOCUMENT_ROOT的工作方式可能有所不同(Apache,IIS,Lighttpd和nginex). cwd显示所选的工作目录,该目录可能正确也可能不正确(您可以在脚本中更改它).所以我建议dirname(__FILE__)

dirname(__FILE__) will always work, regardless of platform or webserver. DOCUMENT_ROOT may work differently between server configurations (Apache vs IIS vs Lighttpd vs nginex). cwd shows the selected working directory which may or may not be correct (you can change it in the script). So I'd suggest dirname(__FILE__)

这篇关于在PHP中创建绝对路径的最佳方法? (请参阅内部列出的3种方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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