Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.50
diff -u -p -r1.50 file.inc
--- includes/file.inc	4 Nov 2005 20:19:14 -0000	1.50
+++ includes/file.inc	6 Nov 2005 10:24:08 -0000
@@ -57,10 +57,10 @@ function file_create_path($dest = 0) {
     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, variable_get('file_directory_temp', file_temporary_directory()))) {
     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 @@ function file_save_upload($source, $dest
   // 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 = variable_get('file_directory_temp', file_temporary_directory());
       $temporary = 1;
       if (is_file($file->filepath)) {
         // If this file was uploaded by this user before replace the temporary copy.
@@ -425,7 +425,7 @@ function file_save_data($data, $dest, $r
     return 0;
   }
 
-  $temp = variable_get('file_directory_temp', ini_get('upload_tmp_dir'));
+  $temp = variable_get('file_directory_temp', file_temporary_directory());
   $file = tempnam($temp, 'file');
   if (!$fp = fopen($file, 'wb')) {
     drupal_set_message(t('The file could not be created.'), 'error');
@@ -551,4 +551,37 @@ function file_scan_directory($dir, $mask
   return $files;
 }
 
+/**
+ * Determine the default temporary directory.
+ */
+function file_temporary_directory() {
+  static $temporary_directory;
+
+  if (is_null($temporary_directory)) {
+
+    // Has PHP been set with an upload_tmp_dir?
+    if (ini_get('upload_tmp_dir')) {
+      $temporary_directory = ini_get('upload_tmp_dir');
+    }
+
+    // Determine based on operating system.
+    elseif (substr(PHP_OS, 0, 3) == 'WIN') {
+      $temporary_directory = variable_get('file_directory_path', 'files') . '\\tmp'; // last resort.
+
+      $directories = array('c:\\windows\\temp', 'c:\\winnt\\temp');
+      foreach ($directories as $directory) {
+        if (is_dir($directory)) {
+          $temporary_directory = $directory;
+          return $temporary_directory;
+        }
+      }
+    }
+
+    else {
+      $temporary_directory = '/tmp';
+    }
+  }
+
+  return $temporary_directory;
+}
 
Index: modules/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system.module,v
retrieving revision 1.251
diff -u -p -r1.251 system.module
--- modules/system.module	3 Nov 2005 19:33:37 -0000	1.251
+++ modules/system.module	6 Nov 2005 10:24:09 -0000
@@ -325,7 +325,7 @@ function system_view_general() {
     '#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 = variable_get('file_directory_temp', file_temporary_directory());
   file_check_directory($directory_temp, FILE_CREATE_DIRECTORY, 'file_directory_temp');
 
   $form['files']['file_directory_temp'] = array(

