检查文件是否已下载 [英] check if file was downloaded

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

问题描述




我使用以下代码提供下载:


header(" Content-Type:$ mimetype" );;

标题(" Content-Disposition:attachment; filename = $ filename");

标题(" Cache-Control:must-revalidate,post-check = 0,pre-check = 0");

header(" Content-Length:" .filesize($ temp_filename));

readfile_chunked($ temp_filename) ;


(readfile_chunked来自
http://nl2.php.net/manual/nl/function.readfile.php


我的问题:如何检查如果文件已下载并保存?我想

下载后可以自动删除。


当用户点击取消并且没有下载时,该功能似乎退出
文件,因此以下所有命令都不会被执行。这是完美的。


然而,它不会在文件小到足以装入块时。 php'的

readfile似乎有相同的行为。所以,在这种情况下,即使点击了取消,所有以下

命令都会被执行(在我的应用程序中,

文件然后被删除,这不应该''当然发生了。)


另外检查发送的字节也无济于事。如果该函数存在,它总是

返回适合单个

块的小文件的完整文件大小,即使单击取消也是如此。


那么,有没有办法确定文件是否已下载并打开/保存
而不是在下载对话框中点击取消?


在此先感谢,最好的问候,

-Hendri Adriaens。

Hi,

I use the following code to offer a download:

header("Content-Type:$mimetype");
header("Content-Disposition: attachment; filename=$filename");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Content-Length:".filesize($temp_filename));
readfile_chunked($temp_filename);

(readfile_chunked comes from
http://nl2.php.net/manual/nl/function.readfile.php)

My question: how can I check if the file was downloaded and saved? I want to
make an automatic removal possible after download.

The function seems to exit when the user clicks cancel and doesn''t download
the file, so all following commands will not get executed. That''s perfect.

However, it doesn''t when the file is small enough to fit in a chunk. php''s
readfile seems to have the same behaviour. So, in that case, all following
commands do get executed, even if cancel was clicked (and in my application,
the file then gets removed, which shouldn''t happen of course).

Also checking the bytes sent doesn''t help. If the function exists, it always
returns the complete filesize for the small files that fit in a single
chunk, even if cancel was clicked.

So, is there any working way to determine if a file was downloaded and
opened/saved instead of cancel being clicked in the download dialog?

Thanks in advance, best regards,
-Hendri Adriaens.

推荐答案

mimetype");

header(" Content-Disposition:attachment; filename =
mimetype");
header("Content-Disposition: attachment; filename=


filename");

header(" Cache-Control:must -revalidate,post-check = 0,pre-check = 0");

header(" Content-Length:" .filesize(
filename");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Content-Length:".filesize(


temp_filename ));

readfile_chunked(
temp_filename));
readfile_chunked(


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

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