how can i set to the top directory (i.e. public_html/folder)?

I have tried $_SERVER['DOCUMENT_ROOT'] without luck.

define('JPATH_BASE', dirname(realpath(__FILE__)). '/folder' );

Recommended Answers

All 6 Replies

Please explain your question more in details so we can help you better. From your question i understand you have path issue, this is your public_html directory but if you hosted your website into a new directory then you have to access your website like this if you are interested to make a varriable for your root path then you can do it with constant for example `

define("SITE_URL", "");


i apologise for my lack of clarification earlier. here is my exact problem:

basically, i have this script which retrieves files and information from various php files in the /public_html/about folder. the script works fine when placed in a file in /public_html/ (the top level of the domain). however, when i move this script to another fold like /public_html/products it stops working.

i know that the issue is that the path i have set is relative (/public_html/ picks it up because it only has to go to /public_html/about to find it.

the issue is with this line (and there are no other problems with the code):

 define('JPATH_BASE', dirname(realpath(__FILE__)). '/about' );

the only way that these files can be retrieved is to alter the code above slightly, so that it uses an absolute path (which can then be used in any folder).

in essence this is my entire coding:


// Set flag that this is a parent file

define( '_JEXEC', 1 );

define('JPATH_BASE', dirname(realpath(__FILE__)). '/about' );


require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe =& JFactory::getApplication('site');

if (!$mainframe->getCfg('offline'))
    echo "Online.";

That is the actual local path on the server, so it should most likely be

define('JPATH_BASE', dirname(realpath(__FILE__)). '\\about' );

it's okay, i've solved it.

define('JPATH_BASE', dirname(realpath(__FILE__)). '/../about' );

Hmm. Wonder if this works differently on different OS. I will have to test it.

Meh, ignore me. I am using a windows server...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.