问题描述
我可以毫无问题地创建路径,但我想知道这 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__) 将始终有效,无论平台或网络服务器如何.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种方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)