On some environments $_SERVER['DOCUMEN_ROOT'] can contain rubbish which has nothing to do with where Drupal is installed. For example, Apache with mod_vhost.

Some modules (eg: search_files) want a full system path for file operations they need to perform and currently use $_SERVER['DOCUMENT_ROOT']. However, this can fail.

Rather than solve this in each module that needs an absolute path reference, it would be good if Drupal contained an API call that reliably returns the actual document root for the current Drupal instance.

The attached patch does just that. It obtains the full path to system.module via __FILE__ and essentially subtracts the value of drupal_get_path() for the system module (and the trailing slash), making it available for all modules via the system_path() call, similar to base_path().

CommentFileSizeAuthor
#2 515358-system-path.patch886 bytescafuego
system-path.patch885 bytescafuego

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

cafuego’s picture

Status: Needs work » Needs review
StatusFileSize
new886 bytes

Fixed missing semicolon (d'oh).

rsaddington’s picture

Patch works fine for me.

Status: Needs review » Needs work

The last submitted patch failed testing.

cafuego’s picture

Status: Needs work » Closed (fixed)

getcwd() for the win