Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.