Commit 7affd91a authored by webchick's avatar webchick
Browse files

#551658 follow-up by pwolanin: Revert back to D6-style temporary folder logic...

#551658 follow-up by pwolanin: Revert back to D6-style temporary folder logic to avoid various platform issues.
parent e0adb930
......@@ -19,7 +19,7 @@
/**
* Minimum supported version of PHP.
*/
define('DRUPAL_MINIMUM_PHP', '5.2.1');
define('DRUPAL_MINIMUM_PHP', '5.2.0');
/**
* Minimum recommended value of PHP memory_limit.
......
......@@ -1957,6 +1957,51 @@ 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".
*/
......@@ -793,7 +793,7 @@ class DrupalTemporaryStreamWrapper extends DrupalLocalStreamWrapper {
* Implements abstract public function getDirectoryPath()
*/
public function getDirectoryPath() {
return variable_get('file_temporary_path', sys_get_temp_dir());
return variable_get('file_temporary_path', file_directory_temp());
}
/**
......
......@@ -752,7 +752,7 @@ class FileDirectoryTest extends FileTestCase {
function testFileDirectoryTemp() {
// Temporary directory handling.
variable_set('file_directory_temp', NULL);
$temp = file_directory_path('temporary');
$temp = file_directory_temp();
$this->assertTrue(!is_null($temp), t('Properly set and retrieved temp directory %directory.', array('%directory' => $temp)), 'File');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment