i have php code , works fine.
header('content-type: application/zip'); header('content-disposition: attachment; filename="wtbak.zip"'); readfile($archivefilename); echo $archivefilename; unlink($archivefilename);
my issue is, how give out message after last line (unlink) has been executed?
thanks!
assumptions:
the client user should receive message, kind of message sent client
the response binary
abstract:
sending binary information client along text response possible if mhtml format, used in mails , each browser has (some nto have) support multipart response. let not chose way
sending binary information respond 1 request (download file) , response request (status of download) - popular practice.
solution:
on server: persist status of download
// pseudocode: log_download_event(seessionid, status='started')
header('content-type: application/zip');
header('content-disposition: attachment; filename="wtbak.zip"');
readfile($archivefilename);
echo $archivefilename;
unlink($archivefilename);
// pseudocode: log_download_event(seessionid, status='done')
on server: implement php respond status of download
// pseudocode: $downloadstatus=get_download_status(sessionid)
echo '{staus:' + $downloadstatus + '}'
on client: on event trigger download
window.open("http://nowhere.com/download.php?resuorce=archive-file.zip");
window.thetrackinterval = window.setinterval(trackdownload, 1000);
var trackinterval = function(){
$.get('ajax/test.html', function(data) {
id(data.status=='ready'){ cleaninterval(window.thetrackinterval); alert('download done'); }
});
}
this solution start sending ajax requests server every 1 second asking "is download done" , when receive confirmation "yest done" client stop tracking , alert message
what missed: implementation of status persistence. not php guy - forgive me gap
Comments
Post a Comment