Gii Gii - 3 months ago 5
PHP Question

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.

Answer

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