Last bit of file path help needed please

Hello,

I have this bit of code at the top of my file to help sort out filepaths.

It works perfectly for my local development server, accessing via domain.com/projectName but fails when accessing via projectName.com

The $projectName varibale is being picked up from the config.php file being included at the top.

Code:

require_once('config.php');

	$currentFolder = basename(dirname(__FILE__));
	if ($currentFolder == $projectName) {
		$currentFolder = $projectName.'/';
	} else {
		$currentFolder = '';
	}
	
	if (substr($_SERVER['DOCUMENT_ROOT'], -1, 1) == '/') {
		$docRoot = substr_replace($_SERVER['DOCUMENT_ROOT'],"",-1);
	} else {
		$docRoot = $_SERVER['DOCUMENT_ROOT'];
	}
	

	
	$phpPath = $docRoot.'/'.$currentFolder;
	$htmlPath = '/'.$projectName.'/';

	require_once($phpPath.'includes/top.php');

The problem is that when accessing via projectName.com the $phpPath variable gets set to:

phpPath = /home/rctneil/public_html/projectName/projectName/

Because of the extra “projectName” it fails.

how can I solve this without breaking it from working on the dev server and via domain.com/projectName

Thanks

Neil

Hello,

$docRoot = $_SERVER[‘DOCUMENT_ROOT’];
line already includes projectName, so you get it twice.

I have sorted out phpPath but htmlPath keeps failing now.

On localhost and domain.com/projectName, $htmlPath should be ‘/projectName/’ but on projectName.com $htmlPath should just be ‘/’.

how can I do this?