我正在尝试查找服务器的 public_html 文件夹中是否存在文件。
第一次尝试:
if ( file_exists('./local-config.php')) {
但这仅在调用上述 if 语句的 php 文件位于同一文件夹中时才有效……不好……
第二次尝试
if ( file_exists( $_SERVER['SERVER_NAME'].'/local-config.php' ) ) {
不工作...
第三次尝试
if ( file_exists( 'http://'. $_SERVER['SERVER_NAME'].'/local-config.php' ) ) {
也不行……
第四次尝试
$_SERVER['DOCUMENT_ROOT'] seems to fall short of my public_html folder!
有任何想法吗?
如果我输入完整路径,我可以让它工作......例如
if ( file_exists( '/home/username/public_html/local-config.php' ) ) {
但这对我没有好处,因为该脚本可以在多个服务器上使用,所以我需要一些通用的东西。
是否可以让 PHP 动态返回 public_html 路径?