Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP CLI include() isn't finding the file

Tags:

Structure of my files is like so:

config.php script |--myscript.php 

myscript.php

<?php require '../config.php'; ?> 

When executing php /path/to/myscript.php I get Warning: require(../config.php): failed to open stream: No such file or directory.

Whats the reason?

like image 434
nick Avatar asked Sep 11 '12 20:09

nick


1 Answers

That's because your current working directory is the one you call your command at, not the one your script is located in.

Use

require __DIR__ . '/../config.php'; 

instead. __DIR__ is a const that points to the directory current file is located in.

like image 200
zerkms Avatar answered Sep 21 '22 12:09

zerkms