file_ensure_htaccess()
Creates a .htaccess file in each Drupal files directory if it is missing.
Related topics
- File interface
- Common file handling functions.
File
- core/includes/file.inc, line 313
- 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_ensure_htaccess() { $private_path = PrivateStream::basePath(); if (! empty ( $private_path )) { } // If a staging directory exists then it should contain a .htaccess file. // @todo https://www.drupal.org/node/2696103 catch a more specific exception // and simplify this code. try { $staging = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } catch (\Exception $e ) { $staging = FALSE; } if ( $staging ) { // Note that we log an error here if we can't write the .htaccess file. This // can occur if the staging directory is read-only. If it is then it is the // user's responsibility to create the .htaccess file. file_save_htaccess( $staging , TRUE); } } |
Please login to continue.