2015-04-05 125 views
2

我可以使用PHP创建带有过期时间的动态下载链接。但是我想在用户完成下载时删除链接。有什么方法可以知道用户何时用PHP或JavaScript完成下载?如何使用PHP或JavaScript检查下载是否完成?

+1

不可靠地使用JavaScript AFAIK。您可以做的最好的事情是在您选择N天,几小时后自动删除文件。这就是为什么所有的网站(*做*都有这样的内容)说:“亲爱的用户,您的下载链接将可用于* N次*。” – 2015-04-05 06:18:57

+0

是否要删除文件或链接文件的链接? – cmbarbu 2015-04-05 07:08:28

+0

相关http://stackoverflow.com/questions/21035294/showing-download-progress-while-downloading-a-file-using-php-and-jquery和http://stackoverflow.com/questions/9245347/download- status-with-php-and-javascript – 2015-04-07 13:15:15

回答

0

使用php页面处理用户请求下载,这会触发它在短时间后删除它?

+0

在一个有快速互联网连接的城镇和在一个移动连接的某个荒凉的村庄里,“短时间”是不一样的 – 2015-04-05 06:23:35

+0

根据文件大小,你可以考虑拨号连接和删除文件很长一段时间后,或24小时后请求。 – Illuminati 2015-04-05 06:35:50

0

这通常是客户端处理。

对于相关问题here可以找到一个很好的答案。

我处理的方式是使用jQuery。在JavaScript中,我会异步启动下载,并且调用函数允许调用回调函数。在此回调函数中,您可以清空与您的下载链接对应的div,并可能向服务器发送消息。

// have a div in your document to call this JavaScript script 
    // first get the file in local memory 
    var file = "myfile.csv"; 
    $.get(file, function(data){ 
     // everything here will be done only when the download is finished 
     // in particular you want the user to be able to get the file using 
     mydoc.execCommand("saveAs",true,".txt"); 

     // as described 
     // here: http://www.webdeveloper.com/forum/showthread.php?12509-how-to-pop-up-Save-As-Window 

     // you can also change the div containing the link/button activating the download 
     // and possibly send the server a download OK signal 

});

+0

如何可靠地说“是的,文件已被客户端成功下载”。 ? – 2015-04-05 06:24:51

+0

这是异步下载功能的工作。它只会在下载完成后才会调用回调函数 – cmbarbu 2015-04-05 06:42:50

+0

请您指出一些解释使用成功的*下载回调*的文档吗? – 2015-04-05 06:43:56

相关问题