I'm coding a download counter and I'd like to know if it is possible to execute code after the buffer (here, a file sent with readfile) have been fully sent by the server and received by the client. Please note I cannot use any clientside language, as I am transferring the file directly (not using XHR or/and FileSystem javascript API).
Is it doable in any way?
Thanks!
possible to execute code after the buffer (here, a file sent with readfile) have been fully sent by the server
Yes....
<?php
readfile($_GET['i_am_so_vuln']);
print "whoops!";
....was that so hard?
and received by the client
No - because you don't when that is. It could be buffered at multiple points on the intervening network. (or even cached).
If it is a file being downloaded by the user, I think you can't echo
anything. I just tested. The file is prompted, it finishes and nothing got printed to the browser. It is important to note that this may depend on the browser.
However, if you try to insert/update a record into a database or save a log file, it works.
So, I would say, you can and you can not.