【问题标题】:require_once $_SERVER['DOCUMENT_ROOT'] . '/defines.php'; not working需要一次 $_SERVER['DOCUMENT_ROOT'] 。 '/defines.php';不工作
【发布时间】:2014-03-23 05:07:21
【问题描述】:

是否可以使用require_once $_SERVER['DOCUMENT_ROOT'] . '/defines.php'; 我一直收到错误消息。

我试过了 require_once ($_SERVER['DOCUMENT_ROOT'] . 'htdocs/comments3/defines.php'); 但它仍然不起作用,请帮助我。

我正在尝试重新创建 https://www.youtube.com/watch?v=X_fJoLdbVyM&list=PLyKBLKYqadGlmL6QLKCicUp9tQsybUII5 的项目 它是一个使用 ajax [Javascript jQuery JSON PHP mysql] 的评论框 但在第 6 集,我无法关注它,因为它开始为该死的 define.php 出错 我使用 C:\xampp\htdocs\cmets 作为我的文件路径

【问题讨论】:

  • 你可以使用任何你想要的东西,只要你正在构建的路径/文件确实存在。由于它不适合您,因此该路径不存在。
  • 请同时提供错误详情。
  • 为什么不回显 $_SERVER['DOCUMENT_ROOT'] 并​​检查路径。
  • 当我查看我的文档时,这是我得到的警告:require_once(C:/xampp/htdocs/so /htdocs/cmets3/defines.php) [function.require-once]:无法打开流:第 1 行的 C:\xampp\htdocs\comment3\index.php 中没有这样的文件或目录致命错误:require_once() [function.require]: 无法打开所需的 'C:/xampp/htdocs/ so cmets3/defines.php' (include_path='.;C:\xampp\php\PEAR') 在 C:\xampp\htdocs\comment3\index.php 第 1 行

标签: php doctype require-once


【解决方案1】:

以下对我有用

require_once ($_SERVER['DOCUMENT_ROOT'] . '/myapp/defines.php');

myapp 是我的应用程序名称。所以以防万一

require_once ($_SERVER['DOCUMENT_ROOT'] . '/comments3/defines.php');

$_SERVER['DOCUMENT_ROOT'] 在 Windows 上指向 C:\Xampp\htdocs,在其他操作系统上类似。所以你需要从那里给出从/开始的路径,所以/comments3/defines.php等等。

如果以上不起作用,请分享defines.php的完整路径

你的情况是comments3而不是comment3的拼写错误

【讨论】:

  • 在这种情况下,上面的方法对你有用,即require_once ($_SERVER['DOCUMENT_ROOT'] . '/comments3/defines.php');
  • 试过它仍然给我警告:require_once(C:/xampp/htdocs/cmets3/defines.php)[function.require-once]:无法打开流:C中没有这样的文件或目录:\xampp\htdocs\comment3\index.php 在第 1 行致命错误:require_once() [function.require]: 无法打开所需的 'C:/xampp/htdocs/cmets3/defines.php' (include_path='.;C :\xampp\php\PEAR') 在第 1 行的 C:\xampp\htdocs\comment3\index.php 中我没有收到此错误我不是专业人士请帮助许多thanx 帮助我真的不明白这一点
  • 您的文件夹名称是comment s 3 或comment3。因为我在 required 和 comment3 中看到 cmets3 作为 index.php 位置
  • 哦,伙计,你做得最好,当我遇到任何问题时,你有联系电子邮件或 Facebook 或 Skype,请 id 喜欢你的帮助
  • 我的邮件/fb/skype 上很少有空,您仍然可以通过me[at]techphernalia[dot]com 给我发邮件,并将其标记为答案。
【解决方案2】:

这样使用

<?php require_once ('defines.php');  ?>

【讨论】:

    猜你喜欢
    • 2013-08-12
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    相关资源
    最近更新 更多