Lingo
Lingo

Reputation: 600

PHP include file in subfolder

I have two files myMenu.php and myView.php

This is my folder:

MyMainFolder
- myMenu.php
- MyViewFolder
--myView.php

Now i want to include myMenu.php into myView.php with include(../myMenu.php);

But this doesnt work. What am I doing wrong?

Upvotes: 0

Views: 33

Answers (1)

Adam J
Adam J

Reputation: 508

You should use it this way:

include(__DIR__."/myMenu.php");

Basically, you're taking the directory that the file you're processing is currently in (__DIR__), and you're telling it to look for that file in the same directory.

You could use this approach to include anything in different directories: include(__DIR__."/../_include/fileName.php")

This would go back one directory from your currently processing file's location, then go in to the _include directory, and look for that file.

Upvotes: 2

Related Questions