无法使用包含

时间:2017-07-04 07:02:03

标签: php phpmyadmin core

大家好,这是一个简单的问题,已经存在堆栈溢出但我尝试了所有可能的答案仍然没有修复

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

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;

}



?>

1 个答案:

答案 0 :(得分: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';

希望这有帮助!