无法使用 include 打开流
failed to open stream using include
你好,这是一个简单的问题,它已经存在于堆栈溢出中,但我尝试了所有可能的答案仍然没有解决
我需要包含资产文件夹下的配置文件我尝试了以下代码
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;
}
?>
检查您的包含路径是否更改并检查 file/folder 权限。
试试这个代码:
<?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';
希望对您有所帮助!
你好,这是一个简单的问题,它已经存在于堆栈溢出中,但我尝试了所有可能的答案仍然没有解决
我需要包含资产文件夹下的配置文件我尝试了以下代码
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;
}
?>
检查您的包含路径是否更改并检查 file/folder 权限。
试试这个代码:
<?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';
希望对您有所帮助!