drupal - How to finish batch and redirect then -


I am working on a Drupal 7 project. I am using a batch, put some operations, and showing progress bar in my "FormulaInterfinished", which is executed in the end, as the last operation of the batch, I want to download a file, And then want to redirect to another page, because the process has ended.

However, the readfile () function uses a drupal_exit (), and therefore my redirection is not done.

This is my code:

function formulaire_finished ($ success, $ result, $ operations) {if ($ success) {$ path = $ result [infos' ] ['Path']; Download_file ($ path); // redirection drupal_goto ($ _ session ['my_page'], array ('query' = & gt; array ('description' => 1 ')); } Else {// An error occurred. // $ includes operations that are unposted $ error_operation = reset ($ operation); Drupal_set_message (t ('error with support' operation during error: @gorge ', array (' @ operation '=> $ error_operation [0],' @args' = & gt; print_r ($ error_operation [0] ], TRUE),))); }}

Download function:

  function download_file ($ path) {$ dir = $ path; $ Filename = basename ($ dir); If (strokes ($ _ server ['HTTP_USER_AGENT'], 'MSIE')) {drupal_add_http_header ('Pragma', 'public'); Drupal_add_http_header ('Cache-Control', 'Required-Re-Modified, Post Check = 0, Pre-Check = 0'); } Other {drupal_add_http_header ('pragma', 'no-cache'); } Drupal_add_http_header ('End', '0'); Drupal_add_http_header ('content-type', 'application / vnd.ms-excel'); Drupal_add_http_header ('content break', 'attachment; file name =' .busname ($ dir). ';'); Drupal_add_http_header ('Content-Transfer-Encoding', 'Binary'); Drupal_add_http_header ('content-length', filesystem ($ dir)); Readfile ($ dir); To unlink ($ dir); Drupal_exit (); }   

All ideas are welcome.

I do not think you want to output the file during the callback of a batch operation needed. You must save the file to the Drupal file system and save the file reference. After the batch is over you can download it.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -