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
- File interface
- Common file handling functions.
File
- core/includes/file.inc, line 1188
- API for handling file uploads and server file management.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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 = ComponentFileSystem::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 ); } // 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 ; } |
Please login to continue.