public function FileSystem::getTempDirectory in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::getTempDirectory()
- 9 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::getTempDirectory()
File
- core/
lib/ Drupal/ Core/ File/ FileSystem.php, line 629
Class
- FileSystem
- Provides helpers to operate on files and stream wrappers.
Namespace
Drupal\Core\FileCode
public function getTempDirectory() {
// Use settings.
$temporary_directory = $this->settings
->get('file_temp_path');
if (!empty($temporary_directory)) {
return $temporary_directory;
}
// Fallback to OS default.
$temporary_directory = FileSystemComponent::getOsTemporaryDirectory();
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);
}
return $temporary_directory;
}