I am running a laravel server using PHP 7. I am trying to require a file using the following:
require __DIR__.'/../bootstrap/autoload.php';
The file I am running this script in is located in a folder called public. So therefore __DIR__
should equal:
www.mydomain.com/myserver/public/index.php
The path the script should create should be:
www.mydomain.com/myserver/bootstrap/autoload.php
However, rather than dynamically create the correct path it is treating the "/../" as a literal directory instead of telling it to go back one. So the path I am getting back is:
www.mydomain.com/myserver/public/../bootstrap/autoload.php
Any ides why this could be happening? Many thanks in advance.
As per my comment;
__DIR__
is the current directory you are in, if you wanted to go back one step, you could use dirname
This is used such as;
dirname(__DIR__);
So, if your current directory is (and is where you actively are):
C:/server/htdocs/system/main/index.php
__DIR__
will give you C:/server/htdocs/system/main
and dirname(__DIR__)
will give C:/server/htdocs/system/
Therefore, using the following will do what you need;
require(dirname(__DIR__) . "/bootstrap/autoload.php");
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