如何检测用户何时成功完成在php中下载文件 [英] How to detect when a user has successfully finished downloading a file in php

查看:618
本文介绍了如何检测用户何时成功完成在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.

这篇关于如何检测用户何时成功完成在php中下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆