php 打开所需文件失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10604519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:35:17  来源:igfitidea点击:

Failed opening required file

php

提问by fuddin

I am getting the following error while running the code,

运行代码时出现以下错误,

Warning: require_once(product.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\pro\application\modules\products\controllers\test1.php on line 2

Fatal error: require_once() [function.require]: Failed opening required 'product.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\pro\application\modules\products\controllers\test1.php on line 2

警告:require_once(product.php) [function.require-once]:无法打开流:第 2 行的 C:\xampp\htdocs\pro\application\modules\products\controllers\test1.php 中没有这样的文件或目录

致命错误:require_once() [function.require]:在 C:\xampp\htdocs\pro\application\modules\ 中打开所需的“product.php”(include_path='.;C:\xampp\php\PEAR')失败第 2 行的产品\控制器\test1.php

The code is simple,

代码很简单,

<?php 
require_once "product.php";

    $array = "I am Fahad and I am testing this code";     
    $start = 4;
    $limit = 9;
    $value =  limit($array, $start, $limit);
    echo $value;
?>

The file product.phplies in the same directory as of the file which I am running. It still is giving an error. Please help out. Thanks

该文件product.php与我正在运行的文件位于同一目录中。它仍然给出错误。请帮忙。谢谢

回答by Justin T.

The actual current directory is not alwaysthe same than the script you are running, especially inside a frameworklike you seem to use right now.

实际的当前目录并不总是与您正在运行的脚本相同,尤其是在您现在似乎正在使用的框架中

To make sure this is working, use

要确保这是有效的,请使用

require_once dirname(__FILE__) . '/product.php';

require_once dirname(__FILE__) . '/product.php';

on 5.3, you can even say :

在 5.3 上,你甚至可以说:

require_once __DIR__ . '/product.php';

require_once __DIR__ . '/product.php';

Hope this helps !

希望这可以帮助 !

回答by Michael Seibt

Check your filenames, especially case sensitivity (product.php != Product.php).

检查您的文件名,尤其是区分大小写(product.php != Product.php)。

回答by Adam Thornton

The error is simple, it can't find the file "product.php" in the place its currently looking.

错误很简单,它在当前查找的位置找不到文件“product.php”。

Personally I would never trust the script to know where to look automatically, I would always try and give absolute paths. For example:

就我个人而言,我永远不会相信脚本会自动知道在哪里查看,我总是会尝试给出绝对路径。例如:

require_once $_SERVER['DOCUMENT_ROOT'] . '/somedir/anotherdir/product.php';