So I'm inferring from the forum post you linked that you're bootstrapping your config with something like NSM bootstrap or similar in order to reduce the pain of moving EE between multiple environments (local/staging/production etc.). That's a great idea, and how I roll with EE myself (though take a look at FocusLabs Master Config for another, more in depth approach to this.
However in this particular case I don't think there's a way to avoid hard coding the URL and server paths for each site, given that $_SERVER is necessarily unaware of any sites other than the current execution context, and MSM doesn't even require you to define your domain anywhere, (leaving aside that we need to do all this before EE has loaded anyway).
That said, we can at least make sure you only have to store that information in as few locations as possible, and still make it easy for multiple dev's to have different absolute paths to their local installs etc, by loading per environment config files, based on an environment constant:
define('EE_SERVER_NAME', $_SERVER['SERVER_NAME']);
switch (EE_SERVER_NAME) {
case 'site1.local';
case 'site2.local';
define('EE_ENV', 'local');
break;
case 'staging.site1.com';
case 'staging.site2.com';
define('EE_ENV', 'staging');
break;
case 'site1.com';
case 'site2.com';
default;
define('EE_ENV', 'production');
break;
}
}
/* load environment specific config file
note you could do this inside the switch above, but setting environment
constants is super useful and gives more flexibility.*/
require_once('./config.'. EE_ENV. '.php');
in config.production.php
define('EE_SITE1_BASE_PATH', '/path/to/site1');
define('EE_SITE1_BASE_URL', 'site1.com');
define('EE_SITE2_BASE_PATH', '/path/to/site2');
define('EE_SITE2_BASE_URL', 'site2.com');
in config.local.php, which is ignored from version control: (include a config.local.example.php to allow new devs to get up and running)
define('EE_SITE1_BASE_PATH', '/different/path/to/site1');
define('EE_SITE1_BASE_URL', 'site1.local');
define('EE_SITE2_BASE_PATH', '/different/path/to/site2');
define('EE_SITE2_BASE_URL', 'site2.local');
upload directories:
//this dir belongs to site 1
9 => array(
'name' => "Images", // Display name in control panel
'server_path' => EE_SITE1_BASE_PATH . '/user/images/', // Server path to upload directory
'url' => EE_SITE1_BASE_URL . '/user/images/' // URL of upload directory
),
//this dir belongs to site 2
10 => array(
'name' => "Blog", // Display name in control panel
'server_path' => EE_SITE2_BASE_PATH . '/user/blog/', // Server path to upload directory
'url' => EE_SITE2_BASE_URL . '/user/blog/' // URL of upload directory
),
As an aside, you should probably use constants like BASE_PATH instead of $base_url, to prevent them being accidentally reassigned, and to make your code/intent clearer to other developers who might come after you.
I've also assumed that you're not trying to declare two upload destinations (one for each site) as a single upload directory definition in config.php. I'm pretty certain that ain't gonna work...