function file_directory_temp

Gets and sets the path of the configured temporary directory.

Return value

mixed|null A string containing the path to the temporary directory.

Related topics

4 calls to file_directory_temp()
ConfigController::downloadExport in drupal/core/modules/config/lib/Drupal/config/Controller/ConfigController.php
Downloads a tarball of the site configuration.
DirectoryTest::testFileDirectoryTemp in drupal/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php
Ensure that the file_directory_temp() function always returns a value.
system_requirements in drupal/core/modules/system/system.install
Test and report Drupal installation requirements.
TemporaryStream::getDirectoryPath in drupal/core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php
Implements Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath()

File

drupal/core/includes/file.inc, line 1881
API for handling file uploads and server file management.

Code

function file_directory_temp() {
  $config = config('system.file');
  $temporary_directory = $config
    ->get('path.temporary');
  if (empty($temporary_directory)) {
    $temporary_directory = file_directory_os_temp();
    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.
    $config
      ->set('path.temporary', $temporary_directory)
      ->save();
  }
  return $temporary_directory;
}