I can create dynamic download link with expire time using PHP. But I want to delete the link when the user completed the download. Is there any way to know when the user has completed the download with PHP or JavaScript?
Asked
Active
Viewed 1,726 times
2
-
1Not reliably using JavaScript AFAIK. The best thing you can do is to automatically delete the file after N days, hours, you choose. That's why all sites (that *do* have something like that) say like "Dear user your download link will be available for *N time*." – Roko C. Buljan Apr 05 '15 at 06:18
-
Do you want to delete the link to the file or the linked file? – cmbarbu Apr 05 '15 at 07:08
-
Related http://stackoverflow.com/questions/21035294/showing-download-progress-while-downloading-a-file-using-php-and-jquery and http://stackoverflow.com/questions/9245347/download-status-with-php-and-javascript – Dan Blows Apr 07 '15 at 13:15
2 Answers
0
Use a php page to process the users request to download, which will trigger it to delete it a short time afterwards?

Illuminati
- 538
- 7
- 22
-
`short time` is not the same in a town with fast internet connection and in some desolated village on a mobile connection – Roko C. Buljan Apr 05 '15 at 06:23
-
Based on the file size you could make it take into account a dial up connection and delete the file a long time after, or 24 hours after requested. – Illuminati Apr 05 '15 at 06:35
0
This is typically handled client side.
You can find a very nice answer to a related question here.
The way I handle that is using jQuery. In JavaScript I launch downloads asynchronously and the calling function allows to call a callback function. In this callback function you can empty the div corresponding to your download link and potentially send a message to the server.
// 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
});
-
How can you reliably say "Yes, the file has been successfully downloaded by the client." ? – Roko C. Buljan Apr 05 '15 at 06:24
-
That is the job of the asynchronous download function. It will call the callback function only when the download is complete – cmbarbu Apr 05 '15 at 06:42
-
Can you please point to some documentation that explains the use of a successful *download callback*? – Roko C. Buljan Apr 05 '15 at 06:43