Include Files from Parent or Other Directory

Include files from parent or other directory

include() and its relatives take filesystem paths, not web paths relative to the document root. To get the parent directory, use ../

include('../somefilein_parent.php');
include('../../somefile_2levels_up.php');

If you begin with a /, an absolute system file path will be used:

// Full absolute path...
include('/home/username/sites/project/include/config.php');

Include files from parent directory

The only thing that comes to my mind right now is the current working directory.

If you don't specify an absolute path the current working directory will be chosen.

E.g.

<?php
chdir("/tmp");
include "test.php"; // will include /tmp/test.php

And

<?php
chdir("/home/marco");
include "test.php"; // will include /home/marco/test.php

Try changing your path to: __DIR__."/../vendor/autoload.php".

See PHP: Magic Constants for further reference.

Include file from parent folder

Check.php

<?php

include "../src/connect.php";

the two dots .. refer to the parent directory.

php.net

include

require

Include PHP file from parent sibling folder in word press

Finally, I found the solution.
just put the dirname(__FILE__) function before the directory that I want to include.

This function will get the directory path that files that I write this function to it.

for example, if file be at C:\xampp\htdocs\amt-master\wp-content\themes\wp-bootstrap-child it returns this path

But as my case, I want to get the previous path to do that I should just put this function in the same function like this

include dirname(dirname(__FILE__))."/filename.php"

then it will return this path

C:\xampp\htdocs\amt-master\wp-content\themes

then you can write remaining path.

Importing modules from parent folder

It seems that the problem is not related to the module being in a parent directory or anything like that.

You need to add the directory that contains ptdraft to PYTHONPATH

You said that import nib worked with you, that probably means that you added ptdraft itself (not its parent) to PYTHONPATH.



Related Topics



Leave a reply



Submit