Jump to content

Recommended Posts

Well as we all know that if your inlcude file is in a directory above what you are in, you can not call a file with inlcude correctly.

 

What do you mean, 'cannot call it wil include correctly'. You can include any file no matter what directory it is in

 

// /docs/includes/config.php
$id = 123;

// /docs/files/index.php
include($_SERVER['DOCUMENT_ROOT'].'docs/includes/config.php');

Seee thats what I wanted. They way I did it in php4 was include ("../inlcude/config.php");

 

I noticed that your root folder is docs, stupidmquestion coming, Is that the same on all hosting?

 

Take that stupid question away, I looked at it a bit more and see what you did.

Seee thats what I wanted. They way I did it in php4 was include ("../inlcude/config.php");

 

I noticed that your root folder is docs, stupidmquestion coming, Is that the same on all hosting?

 

Take that stupid question away, I looked at it a bit more and see what you did.

 

Well like he said you can include any file so long as its on the server its self and you know the directories.

 

Most shared hosts put their system users in /home and your username is usually your directory (it is your directory if they use cPanel)

 

If you don't know the full path to your account you can google around for a little php file that tells you the full directory path its in..

 

After you know what it is you just do it like

 

include("/home/bruno/public_html/mytest/borat.php");

 

*Bruno being your username/directory*

 

 

 

If you don't know the full path to your account you can google around for a little php file that tells you the full directory path its in..

 

Or you could just echo the $_SERVER['DOCUMENT_ROOT'] variable yourself.

 

I like that better since it is not server specific and if I need to deploy my project somewhere else, it works. Plus I have a server on my PC for testing there as well. 

Or, set your include path in a config file

// config.php
set_include_path(get_include_path().PATH_SEPARATOR.$_SERVER['DOCUMENT_ROOT']);

Then you can easily include from this directory no matter where you are

include('classes/xyz.class.php');
include('functions/xyz.func.php');

 

What you did here was to use a relative path

They way I did it in php4 was include ("../inlcude/config.php");

 

The afformentioned above uses absolute paths

 

Or, set your include path in a config file

// config.php
set_include_path(get_include_path().PATH_SEPARATOR.$_SERVER['DOCUMENT_ROOT']);

Then you can easily include from this directory no matter where you are

include('classes/xyz.class.php');
include('functions/xyz.func.php');

 

What you did here was to use a relative path

They way I did it in php4 was include ("../inlcude/config.php");

 

The afformentioned above uses absolute paths

 

Alright so if I set up whatr you just said can I do what I described in my first post because I don't really get include('functions/xyz.func.php'); so basicly I set up that config file u showed my and do ("../inlcude/config.php");

 

Would that work like that?

 

No, again that is a relative path (relative from the directory you are in)

basicly I set up that config file u showed my and do ("../inlcude/config.php");

 

If my webservers document root for my domin abc.com is /var/www/html/abc.com/docs/ (remember a / at the beginning inclidates the root directory of the server. i.e in windows c:\)

If I do

set_include_path(get_include_path().PATH_SEPARATOR.$_SERVER['DOCUMENT_ROOT']);

The this will set the include path to:

/var/www/html/abc.com/docs/

 

So if I have directories under docs/ called functions & classes even if I am within the classes directory I can still use

include('functions/xyz.func.php');

This is because I have set the path where it should look from for includes so it will be looking for:

/var/www/html/abc.com/docs/functions/xyz.func.php

 

This is an absolute path. Don't use relative paths as if you move files/folders it makes it harder to fathom out. Look up the difference between relative & absolute paths.

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.