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?
3
-
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– Roko C. Buljan2015-04-05 06:18:57 +00:00Commented Apr 5, 2015 at 6:18
-
Do you want to delete the link to the file or the linked file?cmbarbu– cmbarbu2015-04-05 07:08:28 +00:00Commented Apr 5, 2015 at 7:08
-
Related stackoverflow.com/questions/21035294/… and stackoverflow.com/questions/9245347/…Dan Blows– Dan Blows2015-04-07 13:15:15 +00:00Commented Apr 7, 2015 at 13:15
Add a comment
|
2 Answers
Use a php page to process the users request to download, which will trigger it to delete it a short time afterwards?
2 Comments
Roko C. Buljan
short time is not the same in a town with fast internet connection and in some desolated village on a mobile connectionIlluminati
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.
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
});
3 Comments
Roko C. Buljan
How can you reliably say "Yes, the file has been successfully downloaded by the client." ?
cmbarbu
That is the job of the asynchronous download function. It will call the callback function only when the download is complete
Roko C. Buljan
Can you please point to some documentation that explains the use of a successful download callback?