【问题标题】:failed to open stream using include无法使用包含打开流
【发布时间】:2017-07-04 07:02:03
【问题描述】:

您好,这是一个简单的问题,堆栈溢出中已经存在,但我尝试了所有可能的答案,但仍未解决

我需要包含资产文件夹下的配置文件我尝试了以下代码

include_once '../config.php' ;

遇到这样的错误

Warning: include(assets/config.php): failed to open stream: No such file or directory in E:\xampp\htdocs\project\assets\handler\ContactHandler.php on line 4

Warning: include(): Failed opening 'assets/config.php' for inclusion (include_path='E:\xampp\php\PEAR') in E:\xampp\htdocs\project\assets\handler\ContactHandler.php on line 4

请建议我在 ContactHandler.php 中包含配置文件的可能方法

ContachHandler.php

<?php

include_once 'E:\xampp\htdocs\project\assets\config.php';

echo "ddddd";
exit;
 include (CONTROLLER.'ContactController.php');
$form = $_POST['form'];
$cnt_controller = new ContactController();
switch ($form)

{

    case 'AddContact':
        $cnt_controller->AddContact($_POST);
        break;
    case 'ContactUs':
    $cnt_controller->ContactUs($_POST);
        break;

}



?>

【问题讨论】:

  • 你的文件路径不正确
  • include_once '../../config.php' ;试试这个
  • include_once '../../config.php' ;include_once '../assets/config.php' ;
  • @vimal 如果路径正确,则授予您文件夹的权限。
  • 我已授予文件夹@NithinJohn 的所有权限,但我仍然无法包含

标签: php phpmyadmin core


【解决方案1】:

检查您的包含路径是否已更改并检查文件/文件夹权限。

试试这个代码:

<?php
$config_path = '../config.php' ;
if (file_exists($config_path)){
    require_once $config_path;
}
else {
    $config_path = 'config.php';
    if (file_exists($config_path)) {
        require_once $config_path;
    }
    else {
        $config_path = '../../config.php';
        require_once $config_path;
    }
}

echo "ddddd";
echo $config_path;
exit;
?> 

测试集静态路径:

include_once 'E:\xampp\htdocs\project\assets\config.php';

希望这会有所帮助!

【讨论】:

  • 感谢@Shafiqul 的建议,它正在进入 if 条件,这意味着文件存在但页面无法正常工作错误
  • 用于测试 include_once 'E:\xampp\htdocs\project\assets\config.php';添加这个
  • 仍然,它显示相同的错误,代码正确并且文件存在于资产中仍然存在包含文件的问题
  • 其实就是进入了我给的if条件 echo"ddd";在需要一次 if 条件之前,如果我删除它显示的 echo 它会在那里停止并打印 ddd 它显示的是相同的错误页面不工作
猜你喜欢
  • 2017-05-16
  • 2017-05-09
  • 2018-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-25
  • 2012-07-22
  • 2012-07-10
相关资源
最近更新 更多