? _tmpdir_anew.patch
? files
? sites/morbus.totalnetnh.net.drupal
Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.50
diff -u -r1.50 file.inc
--- includes/file.inc	4 Nov 2005 20:19:14 -0000	1.50
+++ includes/file.inc	8 Nov 2005 21:08:05 -0000
@@ -27,12 +27,12 @@
  * @return URL pointing to the file
  */
 function file_create_url($path) {
-  if (strpos($path, variable_get('file_directory_path', 'files')) !== false) {
-    $path = trim(substr($path, strlen(variable_get('file_directory_path', 'files'))), '\\/');
+  if (strpos($path, file_directory_path()) !== false) {
+    $path = trim(substr($path, strlen(file_directory_path())), '\\/');
   }
   switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
     case FILE_DOWNLOADS_PUBLIC:
-      return $GLOBALS['base_url'] .'/'. variable_get('file_directory_path', 'files') .'/'. str_replace('\\', '/', $path);
+      return $GLOBALS['base_url'] .'/'. file_directory_path() .'/'. str_replace('\\', '/', $path);
     case FILE_DOWNLOADS_PRIVATE:
       return url('system/files', 'file='. $path, NULL, TRUE);
   }
@@ -48,7 +48,7 @@
  *         Returns FALSE if the path is invalid (i.e. outside the configured 'files'-directory).
  */
 function file_create_path($dest = 0) {
-  $file_path = variable_get('file_directory_path', 'files');
+  $file_path = file_directory_path();
   if (!$dest) {
     return $file_path;
   }
@@ -57,10 +57,10 @@
     return $dest;
   }
   // check if the destination is instead inside the Drupal temporary files directory.
-  else if (file_check_location($dest, variable_get('file_directory_temp', ini_get('upload_tmp_dir')))) {
+  else if (file_check_location($dest, file_directory_temp())) {
     return $dest;
   }
-  // Not found, try again with prefixed dirctory path.
+  // Not found, try again with prefixed directory path.
   else if (file_check_location($file_path . '/' . $dest, $file_path)) {
     return $file_path . '/' . $dest;
   }
@@ -367,7 +367,7 @@
   // Make sure $source exists in $_FILES.
   if ($file = file_check_upload($source)) {
     if (!$dest) {
-      $dest = variable_get('file_directory_temp', ini_get('upload_tmp_dir'));
+      $dest = file_directory_temp();
       $temporary = 1;
       if (is_file($file->filepath)) {
         // If this file was uploaded by this user before replace the temporary copy.
@@ -425,7 +425,7 @@
     return 0;
   }
 
-  $temp = variable_get('file_directory_temp', ini_get('upload_tmp_dir'));
+  $temp = file_directory_temp();
   $file = tempnam($temp, 'file');
   if (!$fp = fopen($file, 'wb')) {
     drupal_set_message(t('The file could not be created.'), 'error');
@@ -551,4 +551,50 @@
   return $files;
 }
 
+/**
+ * Determine the default temporary directory.
+ */
+function file_directory_temp() {
+  $temporary_directory = variable_get('file_directory_temp', NULL);
+
+  if (is_null($temporary_directory)) {
+    $directories = array();
+
+    // Has PHP been set with an upload_tmp_dir?
+    if (ini_get('upload_tmp_dir')) {
+      $directories[] = ini_get('upload_tmp_dir');
+    }
+
+    // Operating system specific dirs.
+    if (substr(PHP_OS, 0, 3) == 'WIN') {
+      $directories[] = 'c:\\windows\\temp';
+      $directories[] = 'c:\\winnt\\temp';
+      $path_delimiter = '\\';
+    }
+    else {
+      $directories[] = '/tmp';
+      $path_delimiter = '/';
+    }
+
+    foreach ($directories as $directory) {
+      if (!$temporary_directory && is_dir($directory)) {
+        $temporary_directory = $directory;
+      }
+    }
+
+    // if a directory has been found, use it, otherwise default to 'files/tmp' or 'files\\tmp';
+    $temporary_directory = $temporary_directory ? $temporary_directory : file_directory_path() . $path_delimiter . 'tmp';
+    variable_set('file_directory_temp', $temporary_directory);
+  }
+
+  return $temporary_directory;
+}
+
+/**
+ * Determine the default 'files' directory.
+ */
+function file_directory_path() {
+  return variable_get('file_directory_path', 'files');
+}
+
 
Index: modules/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system.module,v
retrieving revision 1.251
diff -u -r1.251 system.module
--- modules/system.module	3 Nov 2005 19:33:37 -0000	1.251
+++ modules/system.module	8 Nov 2005 21:08:06 -0000
@@ -317,7 +317,7 @@
   // File system:
   $form['files'] = array('#type' => 'fieldset', '#title' => t('File system settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
 
-  $directory_path = variable_get('file_directory_path', 'files');
+  $directory_path = file_directory_path();
   file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
 
   $form['files']['file_directory_path'] = array(
@@ -325,7 +325,7 @@
     '#description' => t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.')
   );
 
-  $directory_temp = variable_get('file_directory_temp', ini_get('upload_tmp_dir'));
+  $directory_temp = file_directory_temp();
   file_check_directory($directory_temp, FILE_CREATE_DIRECTORY, 'file_directory_temp');
 
   $form['files']['file_directory_temp'] = array(
@@ -961,7 +961,7 @@
  * Menu callback; display theme configuration for entire site and individual themes.
  */
 function system_theme_settings($key = '') {
-  $directory_path = variable_get('file_directory_path', 'files');
+  $directory_path = file_directory_path();
   file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
 
   // Default settings are defined in theme_get_settings() in includes/theme.inc
Index: modules/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user.module,v
retrieving revision 1.526
diff -u -r1.526 user.module
--- modules/user.module	1 Nov 2005 10:17:34 -0000	1.526
+++ modules/user.module	8 Nov 2005 21:08:06 -0000
@@ -1777,7 +1777,7 @@
 
   $form['pictures'] = array('#type' => 'fieldset', '#title' => t('Pictures'));
   $form['pictures']['user_pictures'] = array('#type' => 'radios', '#title' => t('Picture support'), '#default_value' => variable_get('user_pictures', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Enable picture support.'));
-  $form['pictures']['user_picture_path'] = array('#type' => 'textfield', '#title' => t('Picture image path'), '#default_value' => variable_get('user_picture_path', 'pictures'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => variable_get('file_directory_path', 'files') .'/')));
+  $form['pictures']['user_picture_path'] = array('#type' => 'textfield', '#title' => t('Picture image path'), '#default_value' => variable_get('user_picture_path', 'pictures'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => file_directory_path() .'/')));
   $form['pictures']['user_picture_default'] = array('#type' => 'textfield', '#title' => t('Default picture'), '#default_value' => variable_get('user_picture_default', ''), '#size' => 30, '#maxlength' => 255, '#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
   $form['pictures']['user_picture_dimensions'] = array('#type' => 'textfield', '#title' => t('Picture maximum dimensions'), '#default_value' => variable_get('user_picture_dimensions', '85x85'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum dimensions for pictures.'));
   $form['pictures']['user_picture_file_size'] = array('#type' => 'textfield', '#title' => t('Picture maximum file size'), '#default_value' => variable_get('user_picture_file_size', '30'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum file size for pictures, in kB.'));
