检查下载是否完成 [英] check if download is completed

查看:113
本文介绍了检查下载是否完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是 -
什么是最好的方式来检测下载是否完成,
,因为之后我要更新数据库。


$ b $我尝试从php manuel的这些代码中的一些代码,但对我来说并不太多。

 头文件(Content-Type:application / octet-stream); 
标题(Content-Length:.filesize($ file));
标题(Content-Disposition:attachment; filename = $ filename);

//缓冲读取不使用readfile($ file);

if($ fp = fopen($ bestand,'rb')){
while(!feof($ fp)){
$ buf = fread($ fp, 4096);
echo $ buf;
$ bytesSent + = strlen($ buf); / *我们知道有多少字节被发送给用户* /
}
}

if($ bytesSent == filesize($ fp)){
/ /做某事与db
}

感谢在理查德

解决方案

这不是真的告诉你用户的下载是否已经完成。当您已经向用户发送字节时,它会告诉您,但是它没有说明用户实际收到的字节数。



实际上,PHP(这是一个服务器端而不是客户端的语言)没有办法真正检测文件下载完成时间。最好的方法是开始时将数据库中的下载记录下来。如果你完全完全需要知道什么时候下载完成,你必须做一些像嵌入Java小程序或使用Flash的东西。但是,通常在用户的可用性方面通常不是正确答案(为什么要求他们安装Java或Flash才能从您的下载内容)。


My question is - What is the best possible way to detect if a download is completed, because after that I want to update the database.

I try'd some of this code from php manuel, but it doesn't do much for me.

Header ( "Content-Type: application/octet-stream"); 
Header ( "Content-Length: ".filesize($file)); 
Header( "Content-Disposition: attachment; filename=$filename");

// buffered read not using readfile($file);

if ($fp = fopen($bestand, 'rb')) {
    while (!feof($fp)) {
        $buf = fread($fp, 4096);
        echo $buf;
        $bytesSent += strlen($buf);    /* We know how many bytes were sent to the user */
    }     
 }

if ($bytesSent == filesize($fp)) {
    //do something with db
}

thanks in adv, Richard

解决方案

That's not really going to tell you if the download has completed for the user. It will tell you when you have finished sending bytes to the user, but it says nothing about how many of them the user has actually received.

In reality, there is no way with PHP (which is a server-side, not a client-side, language) to truly detect when a file download has completed. The best you can do is log the download in your database when it begins. If you absolutely, completely and totally need to know when the download has completed, you'll have to do something like embed a Java applet or use Flash. However, usually that is not the correct answer in terms of usability for your user (why require them to have Java or Flash installed just to download something from you?).

这篇关于检查下载是否完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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