You are here

function file_save_htaccess in Drupal 8

Creates a .htaccess file in the given directory.

Parameters

string $directory: The directory.

bool $private: (Optional) FALSE indicates that $directory should be a web-accessible directory. Defaults to TRUE which indicates a private directory.

bool $force_overwrite: (Optional) Set to TRUE to attempt to overwrite the existing .htaccess file if one is already present. Defaults to FALSE.

Return value

bool TRUE when file exists or created successfully, FALSE otherwise.

Deprecated

in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Component\FileSecurity\FileSecurity::writeHtaccess() instead.

See also

https://www.drupal.org/node/2940126

Related topics

1 call to file_save_htaccess()
HtaccessDeprecationTest::testDeprecatedFunctions in core/tests/Drupal/KernelTests/Core/File/HtaccessDeprecationTest.php
Tests messages for deprecated functions.

File

core/includes/file.inc, line 358
API for handling file uploads and server file management.

Code

function file_save_htaccess($directory, $private = TRUE, $force_overwrite = FALSE) {
  @trigger_error('file_save_htaccess() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \\Drupal\\Component\\FileSecurity\\FileSecurity::writeHtaccess() instead. See https://www.drupal.org/node/2940126', E_USER_DEPRECATED);
  return \Drupal::service('file.htaccess_writer')
    ->write($directory, $private, $force_overwrite);
}