Srivathsan
Srivathsan

Reputation: 630

Including a file in another directory

I tried to include a file in another directory using php. There are two directories

Name of first directory : 'includes' and it contains a file called sample.php

Name of second directory : 'core' and it contains main.php

I need to include the main.php file in sample.php. I used the following but it still shows the warning saying no such file exists. But the file is live there.

include '../main.php';

So what do I do now ?

Upvotes: 0

Views: 88

Answers (2)

Sergey
Sergey

Reputation: 5207

Try this

include dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR.'main.php'

Upvotes: 1

Igor Chubin
Igor Chubin

Reputation: 64563

You have said that main.php lives in core. Then:

include '../core/main.php';

Upvotes: 0

Related Questions