计算完全下载的文件

时间:2013-07-12 11:02:48

标签: php apache nginx download

是否可以使用nginx或apache(后端的php,但是nginx传送文件)只计算完全文件下载(当用户点击保存对话框时接受)?

1 个答案:

答案 0 :(得分:1)

纯PHP解决方案看起来像这样(简化):

<?php

$file = $_GET['file'];
check_if_file_is_ok_for_download($file);

header('Content-Type: ...');
header('Content-Length: ...');
header('Content-Dispostion: ...'); 
// more headers if necesarry ...

// output the file
readfile($file);

// count the finished download
database_add_finished_download($file);

然后使用下载链接,如:

http://yourserver.com/download.php?file=...

可以将其重写为以下内容:

http://yourserver.com/download/...
相关问题