Niel Sinel
Niel Sinel

Reputation: 291

How can I include PHP files if the file that I'm going to include is located outside the folder of my current PHP file

How can I include PHP files if the file that I'm going to include is located outside the current directory of my php file. It works when I include the the whole directory for example

include 'C:\xampp\htdocs\sample1\samplephpfile.php';

But I know that it is not efficient to use if I uploaded my site in the web server. Help please. Thank you.

Upvotes: 0

Views: 63

Answers (2)

Daniel
Daniel

Reputation: 340

You can define a root path and then use only ROOT_PATH. If you will want to change it you can do it only at one place.

define('ROOT_PATH', 'C:\xampp\htdocs\sample1\');

Upvotes: 1

odedta
odedta

Reputation: 2478

Use ../ to go back one directory, use / to go to root directory.

This article explain this idea further.

Upvotes: 1

Related Questions