You are here

function file_directory_temp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/includes/file.inc \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

7 calls to file_directory_temp()
ConfigController::downloadExport in core/modules/config/src/Controller/ConfigController.php
Downloads a tarball of the site configuration.
ConfigExportImportUITest::testExportImportCollections in core/modules/config/src/Tests/ConfigExportImportUITest.php
Tests an export and import of collections.
ConfigExportUITest::testExport in core/modules/config/src/Tests/ConfigExportUITest.php
Tests export of configuration.
DirectoryTest::testFileDirectoryTemp in core/modules/system/src/Tests/File/DirectoryTest.php
Ensure that the file_directory_temp() function always returns a value.
KernelTestBase::__get in core/tests/Drupal/KernelTests/KernelTestBase.php
BC: Automatically resolve former KernelTestBase class properties.

... See full list

3 string references to 'file_directory_temp'
d6_system_file.yml in core/modules/system/migration_templates/d6_system_file.yml
core/modules/system/migration_templates/d6_system_file.yml
File::initializeIterator in core/modules/file/src/Plugin/migrate/source/d6/File.php
Implementation of MigrateSource::performRewind().
UserPictureFile::initializeIterator in core/modules/user/src/Plugin/migrate/source/d6/UserPictureFile.php
Implementation of MigrateSource::performRewind().

File

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

Code

function file_directory_temp() {
  $temporary_directory = \Drupal::config('system.file')
    ->get('path.temporary');
  if (empty($temporary_directory)) {

    // Needs set up.
    $config = \Drupal::configFactory()
      ->getEditable('system.file');
    $temporary_directory = file_directory_os_temp();
    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);
    }

    // Save the path of the discovered directory. Do not check config schema on
    // save.
    $config
      ->set('path.temporary', (string) $temporary_directory)
      ->save(TRUE);
  }
  return $temporary_directory;
}