文件下载后如何显示邮件? [英] How do I display a message after a file has been downloaded?

查看:151
本文介绍了文件下载后如何显示邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  header('Content-Type:application / zip'); 
header('Content-Disposition:attachment; filename =WTBak.zip');
readfile($ ArchiveFileName);
echo $ ArchiveFileName;
unlink($ ArchiveFileName);

我的问题是,如何在最后一行(取消链接)执行后发出消息



谢谢!

解决方案

假设: strong>


  1. 客户端用户应该收到一条消息,这是发送给客户端的一种消息


  2. 回复为二进制


摘要: strong>


  1. 如果是mhtml格式,用于邮件和每个浏览器都有(有些没有)支持多部分响应。让我们不要这样选择


  2. 发送二进制信息来响应一个请求(下载文件),另一个响应另一个请求(下载状态) - 这是一个


解决方案:


  1. 服务器:持续下载状态



    //伪代码:log_download_event seessionid,status ='started')



    标题('Content-Type:application / zip');



    header('Content-Disposition:attachment; filename =WTBak.zip');



    readfile($ ArchiveFileName);



    echo $ ArchiveFileName;



    unlink($ ArchiveFileName);



    //伪代码: log_download_event(seessionid,status ='done')


  2. 在服务器上:实现一个php, / p>

    //伪代码:$ DownloadStatus = get_download_status(sessionid)



    echo'{staus:'+ $ DownloadStatus +'}'


  3. strong>在某些事件触发下载



    window.open(http://nowhere.com/download.php?resuorce=archive-file.zip);



    window.theTrackInterval = window.setInterval(trackDownload,1000);



    var trackInterval = function()



    $。get('ajax / test.html',function(data){

      id(data.status =='ready'){

    cleanInterval(window.theTrackInterval);

    alert('下载完成');

    }

    });



    }


该解决方案将开始每隔一秒向服务器发送ajax请求下载完成,当它将收到确认已经完成时,客户端将停止跟踪并提醒消息



遗漏了什么:
执行状态持久性。我不是PHP的家伙 - 原谅我这个差距


I have this PHP code and it works fine.

header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="WTBak.zip"');
readfile($ArchiveFileName);
echo $ArchiveFileName;
unlink($ArchiveFileName);

My issue is, how do I give out a message after the last line (unlink) has been executed?

Thanks!

解决方案

Assumptions:

  1. The client user should receive a message, this is kind of message sent to the client

  2. The response is binary

Abstract:

  1. sending binary information to the client along with text response would be possible if it is mhtml format, used in mails and each browser has (some do nto have) the support for multipart response. Let us not chose this way

  2. sending binary information to respond one request (download file) and another response to another request (status of download) - this is a popular practice.

Solution:

  1. on server: persist the status of download

    // pseudocode: log_download_event(seessionid, status='started')

    header('Content-Type: application/zip');

    header('Content-Disposition: attachment; filename="WTBak.zip"');

    readfile($ArchiveFileName);

    echo $ArchiveFileName;

    unlink($ArchiveFileName);

    // pseudocode: log_download_event(seessionid, status='done')

  2. on server: implement a php that will respond with a status of download

    // pseudocode: $DownloadStatus=get_download_status(sessionid)

    echo '{staus:' + $DownloadStatus + '}'

  3. on client: on some event trigger the download

    window.open("http://nowhere.com/download.php?resuorce=archive-file.zip");

    window.theTrackInterval = window.setInterval(trackDownload, 1000);

    var trackInterval = function(){

    $.get('ajax/test.html', function(data) {

    id(data.status=='ready'){
    
        cleanInterval(window.theTrackInterval);
    
        alert('download is done');
    
    }
    

    });

    }

This solution will start sending the ajax requests to the server every one second asking "is download done" and when it will receive confirmation "yest it is done" client will stop tracking and alert a message

What is missed: the implementation of status persistence. i am not PHP guy - forgive me this gap

这篇关于文件下载后如何显示邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆