如何检测用户何时成功完成在php中下载文件
我有一个处理文件下载请求的php页面。我需要能够检测文件何时成功下载。如何才能做到这一点?也许有一些方法可以检测到这个客户端然后向服务器发送确认。
I've got a php page which handles requets for file downloads. I need to be able to detect when a file has been downloaded successfully. How can this be done? Perhaps there's some means of detecting this client-side then sending a confirmation down to the server.
谢谢。
编辑:
通过句柄,我的意思是该页面的行为是这样的:
By handle, I mean that the page is doing something like this:
$file = '/var/www/html/file-to-download.xyz';
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
在单独的php脚本中处理下载(更好的做法)不仅仅是 readfile($ file);
,您还可以提供恢复下载的功能,例如问题)。
然后在这个脚本中,当您读取最后一个块并发送它时,您就知道所有文件都已发送。这与获知所有内容并不相同,但对于大多数情况来说应该足够了。
Handle the download in a seperate php script (better do a little more than just readfile($file);
, you can also provide the ability to resume downloads like in this question).
Then in this script, when you read the last block and send it, you know that all the file was sent. This is not the same as knowing that all was received, but it should be enough for most scenarios.