【发布时间】:2010-12-06 11:57:42
【问题描述】:
检测下载是否完成的最佳方法是什么,因为之后我想更新数据库。
我尝试了 PHP 手册中的一些代码,但它对我没有多大作用:
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
}
【问题讨论】:
-
我找到了一个用纯 PHP 实现的好解决方案:bytes.com/topic/php/answers/…