You are here

function feeds_xls_get_populated_template in Feeds XLS 7

Callback function to actually retrieve the file.

1 string reference to 'feeds_xls_get_populated_template'
feeds_xls_menu in ./feeds_xls.module
Implementation of hook_menu().

File

./feeds_xls.template.inc, line 10

Code

function feeds_xls_get_populated_template() {

  // The path of the XLS file should be saved to a session.
  if (isset($_SESSION['feeds_xls']) && is_array($_SESSION['feeds_xls'])) {

    // We should have the file path in the $results array, so we will output it
    // to the browser.
    switch ($_SESSION['feeds_xls']['writer']) {
      case 'Excel5':
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment; filename="' . $_SESSION['feeds_xls']['importer'] . '.xls"');
        break;
      case 'Excel2007':
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment; filename="' . $_SESSION['feeds_xls']['importer'] . '.xlsx"');
        break;
    }
    header('Cache-Control: max-age=0');
    readfile($_SESSION['feeds_xls']['csv_path'] . '.excel');

    // delete the files
    drupal_unlink($_SESSION['feeds_xls']['csv_path'] . '.excel');
    drupal_unlink($_SESSION['feeds_xls']['csv_path']);
    unset($_SESSION['feeds_xls']);
    exit;
  }
  else {
    drupal_set_message(t('Generation of the populated Excel template has failed'), 'error');
    drupal_goto();
  }
}