【问题标题】:require_once failed to open stream even tho on other pages it works well with no errors即使在其他页面上,require_once 也无法打开流,它运行良好且没有错误
【发布时间】:2023-04-08 21:54:01
【问题描述】:

我在可能不是什么大问题的事情上遇到了这样的困难。

我不断收到错误消息:警告:require(models/match.php) [function.require]:无法打开流:没有这样的文件或目录。

现在我知道它确实可以在同一文件级别的同一目录中工作,但当我将它与其他代码位一起放入时,它已经工作了

代码:

    <?php
define('KICKOFF_REL','../../../../');

set_include_path(KICKOFF_REL);  




require 'models/match.php';



$league_id = 1; //'premier league';
require 'models/league.php';
$theMenuLeagueObj = new league();   
$league_details = $theMenuLeagueObj->fetch_league($league_id);


//require 'models/match.php';
$theMatchObj = new match(); //Create match object
$allAvaliableMatches = $theMatchObj->fetch_all_active_matches($league_details['league_name']);
echo '<table border="1">';
echo '<tr>';
    echo '<th scope="col">'. $league_details['league_name'] . '</th>';
    echo '<th scope="col">'. $league_details['league_name'] . '</th>';
    echo '</tr>';
foreach($allAvaliableMatches as $thematch){




    echo '<tr>
    <td>'. $thematch['home_team'] . " v " . $thematch['away_team'] . '</td>
    <td>Sunday Games</td></tr>';

    }

    echo '</table>';

【问题讨论】:

  • 什么是“其他代码”?

标签: php stream require


【解决方案1】:

其他文件有正确的路径,这个没有。

这就是其他人工作而这个人没有工作的原因。

使用realpath('model/match.php') 来查看PHP 在评估您提供的相对路径 时使用的完整路径

【讨论】:

  • 我也推荐这个; set_include_path(implode(PATH_SEPARATOR, array(realpath(__DIR__ . '/path/to/filedir'), get_include_path())));
【解决方案2】:

当你使用 require、require_once、include 或 include_once 时,你必须检查路径是否正确。检查您是否只需 ctrl+左键单击。如果路径正确,则将打开,否则不会。

【讨论】:

  • CTRL+左键单击?在什么IDE中? OP 没有提到 IDE。
  • 我正在使用 NetBeans,所以它可以在其中工作。它也可以在eclipse和dreamviewer中工作。
  • 我的意思是,您的回答具有误导性,因为它没有提到这将在哪些应用程序/IDE 中起作用。除了许多人既不使用 NetBeans Eclipse 也不使用 DreamWeaver 的事实。
猜你喜欢
  • 2020-03-25
  • 2017-04-27
  • 2018-09-23
  • 1970-01-01
  • 2016-01-30
  • 1970-01-01
  • 2015-02-25
  • 1970-01-01
  • 2020-10-05
相关资源
最近更新 更多