0

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?

1
  • Servers may not always be configured to use paths like that, you can use $_SERVER['DOCUMENT_ROOT']. '/path/to/file.filytype' Commented Apr 4, 2018 at 17:52

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.