You are here

function Xmodule_builder_page_download in Module Builder 6.2

Same name and namespace in other branches
  1. 7 module_builder.module \Xmodule_builder_page_download()

Module form: 'download' step. Download the files.

File

./module_builder.module, line 413
Builds scaffolding for custom modules.

Code

function Xmodule_builder_page_download($form, $form_values) {
  $file_content = '';
  $file_ext = '.txt';
  if ($form_values['op'] == t('Download module')) {
    $file_content = $form_values['module_code'];
    $file_ext = '.module';
  }
  elseif ($form_values['op'] == t('Download info file')) {
    $file_content = $form_values['module_info'];
    $file_ext = '.info';
  }
  else {
    form_set_error('Problem creating file for download.');
    drupal_goto('module_builder');
  }
  if (strlen($file_content) > 0) {
    $file_name = $form_values['module_root_name'] . $file_ext;
    header("Content-disposition: attachment; filename={$file_name}");
    header('Content-Type: application/force-download');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . strlen($file_content));
    header('Pragma: no-cache');
    header('Expires: 0');
    echo $file_content;
    exit;
  }
}