file_directory_temp

  1. drupal
    1. 4.7 file.inc
    2. 5 file.inc
    3. 6
    4. 7
Versions
4.7 – 7 file_directory_temp()

Get the path of system-appropriate temporary directory.

Related topics

▾ 4 functions call file_directory_temp()

DrupalTemporaryStreamWrapper::getDirectoryPath in drupal/includes/stream_wrappers.inc
Implements abstract public function getDirectoryPath()
system_file_system_settings in drupal/modules/system/system.admin.inc
Form builder; Configure the site file handling.
system_requirements in drupal/modules/system/system.install
Test and report Drupal installation requirements.
system_update_7066 in drupal/modules/system/system.install
Migrate the 'file_directory_temp' variable.

Code

drupal/includes/file.inc, line 2324

<?php
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';
      $path_delimiter = '\\';
    }
    else {
      $directories[] = '/tmp';
      $path_delimiter = '/';
    }
    // 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' or 'files\\tmp'.
      $temporary_directory = variable_get('file_public_path', conf_path() . '/files') . $path_delimiter . 'tmp';
    }
    // Save the path of the discovered directory.
    variable_set('file_temporary_path', $temporary_directory);
  }

  return $temporary_directory;
}
?>