2

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
  • 1
    Not 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." Commented Apr 5, 2015 at 6:18
  • Do you want to delete the link to the file or the linked file? Commented Apr 5, 2015 at 7:08
  • Related stackoverflow.com/questions/21035294/… and stackoverflow.com/questions/9245347/… Commented Apr 7, 2015 at 13:15

2 Answers 2

0

Use a php page to process the users request to download, which will trigger it to delete it a short time afterwards?

Sign up to request clarification or add additional context in comments.

2 Comments

short time is not the same in a town with fast internet connection and in some desolated village on a mobile connection
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.
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

});

3 Comments

How can you reliably say "Yes, the file has been successfully downloaded by the client." ?
That is the job of the asynchronous download function. It will call the callback function only when the download is complete
Can you please point to some documentation that explains the use of a successful download callback?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.