1

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.

Gii
  • 25
  • 3
  • 1
    Using the full path rather than a relative path usually solves this sort of thing. ie: `include( $_SERVER['DOCUMENT_ROOT'] . '/connector/connectionUltility.php' );` or use `set_include_path` prior to using `include` – Professor Abronsius Aug 13 '16 at 16:26
  • 1
    @ Ilaya Raja S When you put `..` it goes one folder back so in `index.php` it tries to include it from `www` direction – Tonza Aug 13 '16 at 16:28
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Aug 20 '16 at 08:33

1 Answers1

0

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

Tonza
  • 650
  • 8
  • 17