简体   繁体   中英

php include() error when included from another file

there is my php file structure:

practice-php

  • index.php
  • model
    • model.php
  • connector
    • connectionUtility.php

in model php I write: include '../connector/connectionUtility.php'; in index.php include 'model/model.php';


when I run the 'model.php', there isn't any error, but when I run the 'index.php' the browser show:

require(../connector/connectionUltility.php): failed to open stream: No such file or directory in 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


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'. 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

practice-php

  • index.php
  • model
    • model.php
  • connector
    • 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

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

Sorry for bad english

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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