php - How do I display a message after a file has been downloaded? -


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:

  1. the client user should receive message, kind of message sent client

  2. the response binary

abstract:

  1. 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

  2. sending binary information respond 1 request (download file) , response request (status of download) - popular practice.

solution:

  1. 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')

  2. on server: implement php respond status of download

    // pseudocode: $downloadstatus=get_download_status(sessionid)

    echo '{staus:' + $downloadstatus + '}'

  3. 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