function file_directory_temp

Same name in other branches
  1. 8.9.x core/includes/file.inc \file_directory_temp()

Gets the path of system-appropriate temporary directory.

Related topics

7 calls to file_directory_temp()
DrupalTemporaryStreamWrapper::getDirectoryPath in includes/stream_wrappers.inc
Implements abstract public function getDirectoryPath()
FileDirectoryTest::testFileDirectoryTemp in modules/simpletest/tests/file.test
Ensure that the file_directory_temp() function always returns a value.
SystemArchiverTest::testArchiverTarball in modules/system/system.test
Tests interacting with a tarball archive.
SystemArchiverTest::_testArchiverOutOfPath in modules/system/system.test
Helper to test out-of-path extraction protection.
system_file_system_settings in modules/system/system.admin.inc
Form builder; Configure the site file handling.

... See full list

2 string references to 'file_directory_temp'
system_update_7066 in modules/system/system.install
Migrate the 'file_directory_temp' variable.
UploadUpgradePathTestCase::testUploadUpgrade in modules/simpletest/tests/upgrade/upgrade.upload.test
Test a successful upgrade.

File

includes/file.inc, line 2671

Code

function file_directory_temp() {
    $temporary_directory = variable_get('file_temporary_path', NULL);
    if (empty($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';
        }
        else {
            $directories[] = '/tmp';
        }
        // PHP may be able to find an alternative tmp directory.
        // This function exists in PHP 5 >= 5.2.1, but Drupal
        // requires PHP 5 >= 5.2.0, so we check for it.
        if (function_exists('sys_get_temp_dir')) {
            $directories[] = sys_get_temp_dir();
        }
        foreach ($directories as $directory) {
            if (is_dir($directory) && is_writable($directory)) {
                $temporary_directory = $directory;
                break;
            }
        }
        if (empty($temporary_directory)) {
            // If no directory has been found default to 'files/tmp'.
            $temporary_directory = variable_get('file_public_path', conf_path() . '/files') . '/tmp';
            // Windows accepts paths with either slash (/) or backslash (\), but will
            // not accept a path which contains both a slash and a backslash. Since
            // the 'file_public_path' variable may have either format, we sanitize
            // everything to use slash which is supported on all platforms.
            $temporary_directory = str_replace('\\', '/', $temporary_directory);
        }
        // Save the path of the discovered directory.
        variable_set('file_temporary_path', $temporary_directory);
    }
    return $temporary_directory;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.