-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFileSystem.php
48 lines (40 loc) · 1.21 KB
/
FileSystem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Drupal\Component\FileSystem;
// cspell:ignore winnt
/**
* Provides file system functions.
*/
class FileSystem {
/**
* Discovers a writable system-appropriate temporary directory.
*
* @return string|false
* A string containing the path to the temporary directory, or FALSE if no
* suitable temporary directory can be found.
*/
public static function getOsTemporaryDirectory() {
$directories = [];
// 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 (str_starts_with(PHP_OS, 'WIN')) {
$directories[] = 'c:\\windows\\temp';
$directories[] = 'c:\\winnt\\temp';
}
else {
$directories[] = '/tmp';
}
// PHP may be able to find an alternative tmp directory.
$directories[] = sys_get_temp_dir();
foreach ($directories as $directory) {
if (is_dir($directory) && is_writable($directory)) {
// Both sys_get_temp_dir() and ini_get('upload_tmp_dir') can return paths
// with a trailing directory separator.
return rtrim($directory, DIRECTORY_SEPARATOR);
}
}
return FALSE;
}
}