php – 无法包含文件并且“无法打开流:没有此类文件或目录”警告消息

包含文件时出现以下错误.

 Warning:  require(home2/myusername/public_html/inc/config.PHP) 
 [function.require]: Failed to open stream: No such file or directory in 
 /home2/myusername/public_html/inc/bootstrap.PHP on line 32

 Fatal error:  require() [function.require]: Failed opening required 
 'home2/myusername/public_html/inc/config.PHP' (include_path='.:/usr/lib/PHP:/usr/local/lib/PHP') in 
 /home2/myusername/public_html/inc/bootstrap.PHP on line 32

它在我在Windows PC上运行的localhost中工作正常.但是当我在我的共享托管服务器CentOS上传文件时,我收到了这个错误.

home2 / myusername / public_html / index.PHP包含/inc/bootstrap.PHP,然后尝试包含/inc/config.PHP.文件config.PHP确实存在于服务器上. home2 / myusername / public_html /由函数getcwd()返回.

下面是bootstrap.PHP中发出错误的前几行代码.

define('APP_DIR', 'app');   

if( !defined('APP_ROOT') ){
    $APP_ROOT = trim(getcwd(), '/').'/';
    if(isset($_GET['bootstrap'])) $APP_ROOT .= APP_DIR . '/';
    define('APP_ROOT', $APP_ROOT);
}

if( !defined('ROOT') ){
    $ROOT = str_replace(APP_DIR, '', trim(APP_ROOT, '/'));
    if( strrpos($ROOT, '/') != strlen($ROOT)-1 ) $ROOT .= '/'; 
    define('ROOT', $ROOT);
}

# path to inc/ folder
define('INC', ROOT.'inc/');

# System configuration variables
require INC . 'config.PHP';

我在/public_html/.htaccess中也有一个URL Rewrite.

RewriteRule ^index.PHP$index.PHP?bootstrap [L]

所以,当我浏览example.com/index.PHP时,它会重写为example.com/index.PHP?bootstrap.这是我得到错误的情况.

这是我的目录结构:

/public_html/
    |__ inc
    |   |__ bootstrap.PHP
    |   |__ config.PHP
    |__ .htaccess
    |__ index.PHP <--- I'm browsing this    

我认为这个问题与绝对路径文件包含有关.相对路径文件包括index.PHP中的require’inc / bootstrap.PHP是可以的.

解决方法:

如果您的文件位于:

/home2/myusername/public_html/index.PHP

你要包含的bootstrap.PHP文件位于:

/home2/myusername/public_html/inc/bootstrap.PHP

你的包含行是否正确:

include_once $_SERVER [‘DOCUMENT_ROOT’].“/ inc / bootstrap.PHP”;

$_SERVER [‘DOCUMENT_ROOT’]等于/ home2 / myusername / public_html

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...