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?
Use a php page to process the users request to download, which will trigger it to delete it a short time afterwards?
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
});