--- modules/search_attachments/search_attachments.module	2009-07-13 14:51:16.000000000 +1000
+++ modules/search_attachments/search_attachments.module	2009-07-13 14:02:11.000000000 +1000
@@ -106,7 +106,7 @@
         $file = db_fetch_object(db_query("SELECT f.*, d.data, u.nid FROM {files} f JOIN {upload} u USING(fid) INNER JOIN {search_dataset} d ON f.fid = d.sid WHERE fid = %d", $item->sid));
 	if (isset($file->nid)) {
 	  $node = node_load($file->nid);
-	  $file->absolute_path = $_SERVER['DOCUMENT_ROOT'] . $base_path . $file->filepath;
+	  $file->absolute_path = search_files_document_root() . $base_path . $file->filepath;
 	  if (is_file($file->absolute_path)) {
 	    $file->info = (object)pathinfo($file->absolute_path);
 	    $results[] = array(
@@ -152,7 +152,7 @@
  */
 function _search_attachments_index_file($file) {
   global $base_path;
-  $contents = _search_attachments_get_file_contents($_SERVER['DOCUMENT_ROOT'] . $base_path . $file->filepath);
+  $contents = _search_attachments_get_file_contents(search_files_document_root() . $base_path . $file->filepath);
   if ($contents) $contents = search_files_convert_to_utf8("{$file->filename} ". $contents);
   search_index($file->fid, 'attachment', $contents);
   return $contents;
@@ -198,4 +198,4 @@
     '#return_value' => 1,
   );
   return system_settings_form($form);
-}
\ No newline at end of file
+}
--- modules/search_directories/search_directories.module	2009-07-13 14:51:16.000000000 +1000
+++ modules/search_directories/search_directories.module	2009-07-13 14:51:46.000000000 +1000
@@ -108,7 +108,7 @@
         return NULL;
       }
 
-      $doc_root = $_SERVER['DOCUMENT_ROOT'];
+      $doc_root = search_files_document_root();
       //drupal_set_message($doc_root);
       $file_extensions = search_files_get_file_extensions();
       $results = array();
@@ -341,7 +341,7 @@
     '#size' => 80,
     '#maxlength' => 150,
     '#required' => true,
-    '#description' => t('The path of the directory to search. Relative pathes are based on %directory.', array('%directory' => getcwd())),
+    '#description' => t('The path of the directory to search. Relative pathes are based on %directory.', array('%directory' => search_path_document_root())),
   );
   $form['submit'] = array(
     '#type' => 'submit',
@@ -367,7 +367,7 @@
   $result = db_query("INSERT INTO {search_directories} (directory) VALUES ('%s')", $directory);
   $directory = $form_state['values']['search_files_directory'];
   if (!preg_match('/^\//', $directory)) {
-    $directory = sprintf("%s/%s", getcwd(), $directory);
+    $directory = sprintf("%s/%s", search_path_document_root(), $directory);
   }
   $directory = preg_replace('/\/+$/', '', $directory);
   $result = db_query($sql, $directory, $form_values['values']['search_files_label']);
--- search_files.module	2009-07-13 14:51:16.000000000 +1000
+++ search_files.module	2009-07-13 14:05:36.000000000 +1000
@@ -437,4 +437,17 @@
 
 function search_files_settings() {
   return '';
-}
\ No newline at end of file
+}
+
+/**
+ * Get the document root for the current Drupal installation.
+ * $_SERVER['DOCUMENT_ROOT'] is not reliable across all
+ * systems, so we need a way to get the correct value.
+ *
+ * @return (string)
+ */
+function search_files_document_root() {
+  $absolute_dir = dirname(__FILE__);
+  $relative_dir = drupal_get_path('module', 'search_files');
+  return substr($absolute_dir, 0, -1 * (1+strlen($relative_dir)));
+}
