简体   繁体   English

如何检查是否使用PHP在下载对话框中单击了保存按钮?

[英]How to check if the save button is clicked on download dialog box using PHP?

There are some files on my site that users can download them. 我的网站上有一些文件可供用户下载。 I use PHP header() to read the files and show download dialog to users. 我使用PHP header()读取文件并向用户显示下载对话框。

I have to increase the download count. 我必须增加下载数量。 So I need to detect if the file is really downloaded. 所以我需要检测文件是否真的下载了。

May be a way is to know if the user clicks save or cancel button or some approach using PHP on the server. 一种可能是知道用户是否单击“保存”或“取消”按钮,或者是使用服务器上的PHP的某种方法。

Would you help me on this issue? 您能在这个问题上帮助我吗? how can I check if the save button is clicked or not? 如何检查是否单击了保存按钮?

You can only detect the initial request. 您只能检测初始请求。 You can not detect whether the file successfully downloaded or not. 您无法检测文件是否成功下载。

Based on this, you would need to implement a count logic when you generate the download; 基于此,在生成下载文件时,您将需要实现一个计数逻辑。 at a similar location where you make the header() call. 在您调用header()的类似位置。

edit: you could track the session/remote ip of the user and ignore subsequent requests to the file within a specific timeframe: 编辑:您可以跟踪用户的会话/远程IP,并忽略在特定时间段内对该文件的后续请求:

You can not detect whether the file successfully downloaded or not as per answer you have received...because what if user has closed your website? You can not detect whether the file successfully downloaded or not根据收到的答案You can not detect whether the file successfully downloaded or not ...因为如果用户关闭了网站怎么办? then you no longer attached with user browser activity. 那么您将不再附加用户浏览器活动。 So it is not possible to track whether file is downloaded. 因此,无法跟踪文件是否已下载。

Yes you can add counter same as visit counter using session as you have seen many example on website while starting learning about session in php. 是的,您可以使用会话添加与访问计数器相同的计数器,因为您开始在php中学习会话时已经在网站上看到了很多示例。

@Ben Rowe's answer sums it up. @Ben Rowe的答案总结了这一点。

You could use a CDN like Amazon's Cloudfront if you're concerned about bandwidth limitations. 如果您担心带宽限制,可以使用像Amazon Cloudfront这样的CDN。 It's free for the first year too 第一年也是免费的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM