【问题标题】:PHP include not working?PHP 包括不工作?
【发布时间】:2014-07-20 22:53:11
【问题描述】:

我只花了大约 45 分钟的时间就让它不起作用我的代码在这里:

<?php 
$path = dirname(__FILE__); 

include("{$path}//config.inc.php"); 
include("{$path}//mc.inc.php"); 

?> 

这就是网页显示的内容:

警告:include(C:\xampp\htdocs\NationKong site\core//mc.inc.php):无法打开流:C:\xampp\htdocs\NationKong site\core\ 中没有这样的文件或目录第 6 行的 init.inc.php

警告:include():无法打开“C:\xampp\htdocs\NationKong site\core//mc.inc.php”以包含 (include_path='.;C:\xampp\php\PEAR') C:\xampp\htdocs\NationKong site\core\init.inc.php 在第 6 行 $配置 服务器状态

【问题讨论】:

    标签: php apache include xampp


    【解决方案1】:

    您在 Windows 上,目录分隔符是 \,在 php 字符串中它将是 "\\" 所以你应该写

    <?php 
    $path = dirname(__FILE__); 
    
    include("{$path}\\config.inc.php"); 
    include("{$path}\\mc.inc.php"); 
    ?> 
    

    如果你想让 php 为你确定正确的目录分隔符,只需使用DIRECTORY_SEPARATOR

    <?php 
    $path = dirname(__FILE__); 
    
    include($path.DIRECTORY_SEPARATOR."config.inc.php"); 
    include($path.DIRECTORY_SEPARATOR."mc.inc.php"); 
    ?> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 2013-07-31
      • 2011-12-01
      • 2018-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      相关资源
      最近更新 更多