【问题标题】:error come when set path to config.php [duplicate]设置 config.php 的路径时出现错误 [重复]
【发布时间】:2012-12-06 10:43:24
【问题描述】:

可能重复:
PHP: Warning: include failed to open stream no such file or directory on Windows

我的主文件夹是 play。它包含 config.php 和登录文件夹

登录文件夹有一个名为ckeditor 的子文件夹,它包含子文件夹_samples。它有我的 php 文件 selectnew.php

我想在 selectnew.php 中包含 config.php。

我设置的路径如下:

include('play\config.php');

我也试过了

include('play/config.php');

但结果如下:

Warning: include(play/config.php) [function.include]: failed to open stream: No such file or directory in D:\wamp\www\play\logins\ckeditor\_samples\selectnew.php on line 7

Warning: include() [function.include]: Failed opening 'play/config.php' for inclusion (include_path='.;C:\php5\pear') in D:\wamp\www\play\logins\ckeditor\_samples\selectnew.php on line 7

我的文件夹

play  folder
    --config.php
   logins folder
      ckeditor  folder
              _samples folder
           selectnew.php

【问题讨论】:

    标签: php ckeditor


    【解决方案1】:

    您必须从当前目录向上移动 2 个文件夹(假设您的 _samples 包含您的 selectnew.php)

    include("../../config.php");
    

    ..或者你可以使用这种方法从根文件夹遍历

    include($_SERVER['DOCUMENT_ROOT']."config.php");
    

    顺便说一句,您的代码不起作用,因为您使用的是当前文件目录的相对路径。所以基本上,当你做 include("play/config.php") 代码会尝试包含这个文件

    play/ckeditor/_samples/play/config.php

    不存在的。

    【讨论】:

    • 它运行良好,谢谢 - 它也适用于 Linux 吗?如果不起作用,它是如何设置的
    【解决方案2】:

    走这条路D:\wamp\www\play\logins\ckeditor\_samples\selectnew.php,你应该使用

    include('../../config.php');
    

    ../ 倒退了一步。因此,如果您返回两次,您将位于 play 文件夹中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      • 1970-01-01
      • 2015-01-20
      • 2021-02-15
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多