You are here

function fckeditor_get_document_root_full_path in FCKeditor - WYSIWYG HTML editor 6.2

Guess the absolute server path to the document root Usually it should return $_SERVER['DOCUMENT_ROOT']

@todo Improve me!! Returns absolute path or false on failure

Return value

string|boolean

1 call to fckeditor_get_document_root_full_path()
fckeditor_resolve_url in ./fckeditor.lib.inc
Emulates the asp Server.mapPath function. Given an url path return the physical directory that it corresponds to.

File

./fckeditor.lib.inc, line 41
FCKeditor - The text editor for Internet - http://www.fckeditor.net Copyright (C) 2003-2008 Frederico Caldeira Knabben

Code

function fckeditor_get_document_root_full_path() {
  $found = 0;
  $index_dir = realpath(dirname($_SERVER['SCRIPT_FILENAME']));

  // {/dir1/dir2/home/drupal}/index.php
  if (getcwd() == $index_dir) {
    $found++;
  }
  $drupal_dir = base_path();
  $index_dir = str_replace('\\', "/", $index_dir);
  $drupal_dir = str_replace('\\', "/", $drupal_dir);
  $document_root_dir = $index_dir . '/' . str_repeat('../', substr_count($drupal_dir, '/') - 1);
  $document_root_dir = realpath($document_root_dir);
  $document_root_dir = rtrim($document_root_dir, '/\\');
  if ($document_root_dir == $_SERVER['DOCUMENT_ROOT']) {
    $found++;
  }
  $document_root_dir = str_replace('\\', '/', $document_root_dir);
  if ($document_root_dir != '') {
    $found++;
  }
  if (file_exists($document_root_dir)) {
    $found++;
  }
  if (file_exists($document_root_dir . base_path() . 'includes/bootstrap.inc')) {
    $found++;
  }
  if ($found >= 3) {
    return $document_root_dir;
  }
  else {
    return FALSE;
  }
}