function FileSystem::getTempDirectory

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::getTempDirectory()
  2. 8.9.x core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::getTempDirectory()
  3. 10 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::getTempDirectory()

Overrides FileSystemInterface::getTempDirectory

File

core/lib/Drupal/Core/File/FileSystem.php, line 610

Class

FileSystem
Provides helpers to operate on files and stream wrappers.

Namespace

Drupal\Core\File

Code

public function getTempDirectory() {
    // Use settings.
    $temporary_directory = $this->settings
        ->get('file_temp_path');
    if (!empty($temporary_directory)) {
        return $temporary_directory;
    }
    // Fallback to OS default.
    $temporary_directory = FileSystemComponent::getOsTemporaryDirectory();
    if (empty($temporary_directory)) {
        // If no directory has been found default to 'files/tmp'.
        $temporary_directory = PublicStream::basePath() . '/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);
    }
    return $temporary_directory;
}

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