Jump to content

[SOLVED] Includes??


FirePhoenix

Recommended Posts

well actually I was meaning like does it have to be in the same directory as the page thats pulling it or can it be in a different directory...

 

I tried

<?php
include ("config.php");
?>

 

and it works fine with the file in the same directory but it I do this

 

<?php
include ("/admin/config.php");
?>

 

with it in a different directory it wont work

Link to comment
https://forums.phpfreaks.com/topic/40048-solved-includes/#findComment-193709
Share on other sites

I see what you mean now.

 

If you want to include a file that is outside of the directory you are in, say you are in mysite/folder1 and you want to include a file that is mysite/folder2 (different directory) then you will use ../ to go one higher in the directory tree. So to get the file that is in mysite/folder2 you'd use this:

 

<?php
include "../folder2/myfile.php";
?>

 

So to get a file that is out side of folder1 and mysite folders you'd use this instead:

<?php
include "../../myfile.php";
?>

 

So the first ../ is to go out of the folder1 directory then the secound ../ is to go out of the mysite directory.

 

Hope that helps.

 

You can of course use absolute paths as well rather than relative paths (what I just showed you). But relative paths are much shorter and cleaner to use.

Link to comment
https://forums.phpfreaks.com/topic/40048-solved-includes/#findComment-193714
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.