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()返回.
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
/home2/myusername/public_html/inc/bootstrap.PHP
你的包含行是否正确:
include_once $_SERVER [‘DOCUMENT_ROOT’].“/ inc / bootstrap.PHP”;
$_SERVER [‘DOCUMENT_ROOT’]等于/ home2 / myusername / public_html