diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-06-12 08:15:15 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-06-12 08:15:15 +0000 |
commit | 7affd91ab6cbef068b56d050c20224382d922d7f (patch) | |
tree | ad200702d794fa1f85e365e995db753cd46250ba /includes/file.inc | |
parent | e0adb9306466fc738004e071e3f9b063441814e2 (diff) | |
download | brdo-7affd91ab6cbef068b56d050c20224382d922d7f.tar.gz brdo-7affd91ab6cbef068b56d050c20224382d922d7f.tar.bz2 |
#551658 follow-up by pwolanin: Revert back to D6-style temporary folder logic to avoid various platform issues.
Diffstat (limited to 'includes/file.inc')
-rw-r--r-- | includes/file.inc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/includes/file.inc b/includes/file.inc index 13a97e56b..dc6b53e96 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -1958,5 +1958,50 @@ function drupal_tempnam($directory, $prefix) { } /** + * Get the path of system-appropriate 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 = '/'; + } + // PHP may be able to find an alternative tmp directory. + $directories[] = sys_get_temp_dir(); + + foreach ($directories as $directory) { + if (is_dir($directory) && is_writable($directory)) { + $temporary_directory = $directory; + break; + } + } + + // if a directory has been found, use it, otherwise default to 'files/tmp' or 'files\\tmp'; + if (empty($temporary_directory)) { + $temporary_directory = file_directory_path() . $path_delimiter .'tmp'; + } + // Save the path of the discovered directory. + variable_set('file_directory_temp', $temporary_directory); + } + + return $temporary_directory; +} + +/** * @} End of "defgroup file". */ |