Hi to Experts,
I've got it working and it was nasty.
First to clarify the scenario - page2 has no representational layer. It uses only to - send header("content-type") + data to browser.
Regarding:
alternatively, in stead of displaying the files list again (with outdated statuses) after a download dialog box has been opened, just display "return to the list" so that when the dialog closes, the user may click on the link... and get an updated page.
I'd tried to implement hereabove solution but with no success.
Putting the "Return to List link" on page2 before header("content-type") and others are send requires setting output_buffer to 'On' in php.ini but...once the link is show up on page2 the download dialog box would not open. Alternatively, putting this link after headers being send line cause that download dialog box is opened but the "Return to List" link simply would not show up at all.
With regards to:
On page2, do this :
- say BODY Unload="SetTimer(downloaddone,2000)" to a function like this : (PS I didn't check the JScript syntax)
Code:
function downloaddone() {
window.opener.reload();
window.close();
}
- send header("content-type") + data to browser
even better IMHO : don't use OnLoad with a 3s timer ; use OnUnLoad() on page2's window
Generally speaking I had a feeling that this is the right direction to resolve the issue, but it wasn't exactly applied to my case because page2 doesn't have any HTML content and so <Body OnLoad=...> is not feasible. It also meanless to use it on page1 as it cause to endless refreshing loop. What I did tried is to change the trigger event to <Body onactivate=...>, so once the dialog window closed the focus returns to page1 window triggering by this refresh() call
routine (aka downloaddone). That was better but since I have some other javascripts that are embedded within page1 code (like I have script which checks multiple checkboxes on that page fired by single selection) it caused the the page1 being refreshed even when it's not required.
Finally, what's worked for me is hereunder solution:
At page2 I used following structure:
<script>
window.location = url(of page1);
setTimeout("window.location.reload(true)",1000);
</script>
<?
header( 'Content-type: ' . $ftype );
header( 'Content-Length: ' . $fsize );
header("Content-Disposition: attachment; filename=$name");
exit;
?>
The time delay seems to be essential otherwise the redirection to page1 occurs immediately, skipping headers send lines in code so the download dialog is not opened. (I'd figured it out because the code copies download file at tmpdownload folder on server before headers are send, by noticing that file was copied but no download window was appeared).
So time delay made it out - have no clue why it acts this way.
Conclusion:
The core of solution is at -
window.location.reload(true);
the thing is to find right place to locate it in code and and generically absorb it within.
Also, other proposed solutions may work depends on case and code design constellation.
Thanks for support and Best Regards,
M.D.