3 namespace Drupal\Component\FileSystem;
6 * Provides file system functions.
11 * Discovers a writable system-appropriate temporary directory.
13 * @return string|false
14 * A string containing the path to the temporary directory, or FALSE if no
15 * suitable temporary directory can be found.
17 public static function getOsTemporaryDirectory() {
20 // Has PHP been set with an upload_tmp_dir?
21 if (ini_get('upload_tmp_dir')) {
22 $directories[] = ini_get('upload_tmp_dir');
25 // Operating system specific dirs.
26 if (substr(PHP_OS, 0, 3) == 'WIN') {
27 $directories[] = 'c:\\windows\\temp';
28 $directories[] = 'c:\\winnt\\temp';
31 $directories[] = '/tmp';
33 // PHP may be able to find an alternative tmp directory.
34 $directories[] = sys_get_temp_dir();
36 foreach ($directories as $directory) {
37 if (is_dir($directory) && is_writable($directory)) {
38 // Both sys_get_temp_dir() and ini_get('upload_tmp_dir') can return paths
39 // with a trailing directory separator.
40 return rtrim($directory, DIRECTORY_SEPARATOR);