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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With