Hello,
In the admin area (orders), I have a custom addon with a post controller orders.post.php. It is sending and receiving data between an external system using CURL. The exchange of the data itself is a success, but the problem arises with the code shown below when I need to present the results to the user:
if ($mode == 'generate_pdf_label') {
.
.
some code omitted, the problematic part is shown below
.
.
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="label.pdf"');
readfile($pdf_download_URL); // this will push the file directly to the output buffer
fn_set_notification('N', fn_get_lang_var('label_created_successfully'));
return array(CONTROLLER_STATUS_REDIRECT, "orders.details?order_id=$_REQUEST[order_id]");
}
The problem here is that the readfile() successfully returns the PDF file to the browser, but it also “exits” the code right after that, so the PHP never reaches the fn_set_notification()-function or the CONTROLLER_STATUS_REDIRECT.
This is exactly what I am trying to achieve:
- In orders.details page I click link that will take me to the orders.generate_pdf_label (the post controller shown above)
- Some data is being exchanged between an external system
- External system returns me an external URL where the PDF label is stored at
- I need to push that PDF to the browser (the readfile()-function)
- Then I need to show a notification and “redirect” back to the orders.details page to get the page “refreshed”
Any ideas on how to achieve this are greatly appreciated!
Best regards,
Simo