You are here

function htaccess_download in Htaccess 7.2

1 string reference to 'htaccess_download'
htaccess_menu in ./htaccess.module
Implementation of hook_menu()

File

./htaccess.admin.inc, line 370
Administration pages.

Code

function htaccess_download($id) {
  $htaccess_get = db_select('htaccess', 'h')
    ->fields('h')
    ->condition('id', array(
    ':id' => $id,
  ), 'IN')
    ->execute()
    ->fetchAssoc();
  $htaccess_content = $htaccess_get['htaccess'];

  // Remove utf8-BOM
  $htaccess_content = str_replace("", '', $htaccess_content);
  $file_name = $htaccess_get['name'] . '.htaccess';
  $htaccess_folder = 'public://htaccess';
  if (file_prepare_directory($htaccess_folder, FILE_CREATE_DIRECTORY)) {
    file_create_htaccess($htaccess_folder, true, false);
    $htaccess_file = file_unmanaged_save_data($htaccess_content, $htaccess_folder . '/' . $file_name, FILE_EXISTS_REPLACE);
    file_transfer($htaccess_file, array(
      'Content-Type' => 'application/octet-stream',
      'Content-disposition' => 'attachment; filename=' . $file_name,
    ));
  }
}