简体   繁体   English

从另一个文件中包含php include()错误

[英]php include() error when included from another file

there is my php file structure: 有我的PHP文件结构:

practice-php 实践PHP

  • index.php 的index.php
  • model 模型
    • model.php model.php
  • connector 连接器
    • connectionUtility.php connectionUtility.php

in model php I write: include '../connector/connectionUtility.php'; 在我写的模型php中:include'../connector/connectionUtility.php'; in index.php include 'model/model.php'; 在index.php中包含'model / model.php';


when I run the 'model.php', there isn't any error, but when I run the 'index.php' the browser show: 当我运行'model.php'时,没有任何错误,但是当我运行'index.php'时,浏览器会显示:

require(../connector/connectionUltility.php): failed to open stream: No such file or directory in C:\\wamp64\\www\\php-practice\\model\\model.php require(../ connector / connectionUltility.php):无法打开流:C:\\ wamp64 \\ www \\ php-practice \\ model \\ model.php中没有这样的文件或目录

Fatal error: require(): Failed opening required '../connector/connectionUltility.php' (include_path='.;C:\\php\\pear') in C:\\wamp64\\www\\php-practice\\model\\model.php 致命错误:require():在C:\\ wamp64 \\ www \\ php-practice \\ model \\ model中打开所需的'../connector/connectionUltility.php'(include_path ='。; C:\\ php \\ pear')失败。 PHP


I found out the answer for my question. 我找到了问题的答案。 If I write: include 'connector/connectionUtility.php' in 'model.php', then I only need to inlcude 'model.php' in 'index.php'. 如果我写'在'model.php'中包含'connector / connectionUtility.php',那么我只需要在'index.php'中包含'model.php'。 The System will still understand. 系统仍然会理解。


Thank you all for helping. 谢谢大家的帮助。

Try to use ../connector/connectionUltility.php in model.php and connector/connectionUltility.php in index.php 尝试使用../connector/connectionUltility.phpmodel.phpconnector/connectionUltility.php中的index.php

practice-php 实践PHP

  • index.php 的index.php
  • model 模型
    • model.php model.php
  • connector 连接器
    • connectionUtility.php connectionUtility.php

../connector/connectionUltility.php dots .. mean that it goes one folder backwards so in model.php it goes back to practice-php direction than it goes to connection/connectionUtility.php ../connector/connectionUltility.php dots ..意味着它向后移动一个文件夹所以在model.php它会回到practice-php方向,而不是connection/connectionUtility.phpconnection/connectionUtility.php

But when you use it in index.php that is already in practise-php direction and because of dots .. it goes back to www direction than it tries to go connector/connectionUltility.php 但是当你在index.php中使用它时已经在practise-php方向和因为点..它会回到www方向,而不是尝试去connector/connectionUltility.php

Sorry for bad english 抱歉英文不好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM