简体   繁体   中英

How to check if a download is complete using PHP or JavaScript?

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?

使用php页面处理用户的下载请求,这将触发它在短时间内将其删除吗?

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

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM