PHP无法打开流,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

我认为这个问题与绝对路径文件包含有关.相对路径文件包括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

标签:php,include,file,centos

来源: https://codeday.me/bug/20190825/1716752.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值