Maison  >  Article  >  développement back-end  >  html - 对一个文件进行发送了下载请求,php能记录下这次请求么,可以通过什么来记录这个请求?

html - 对一个文件进行发送了下载请求,php能记录下这次请求么,可以通过什么来记录这个请求?

WBOY
WBOYoriginal
2016-08-04 09:19:37835parcourir

如题,没有代码描述。
或者通过配置apache,怎么来记录这次请求

回复内容:

如题,没有代码描述。
或者通过配置apache,怎么来记录这次请求

<code>download.php?file=work.zip
<?php $filepath = '/data/'.trim($_GET['file']);
if(file_exists($filepath)) {
    log($filepath);
}
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
//方法1:交给Nginx输出(Nginx有AIO线程池,不会阻塞)
header("X-Accel-Redirect: $filepath");
//方法2:PHP自己输出(PHP进程会被阻塞)
//readfile($filepath);</code></code>

最简单的方法:用户下载文件先请求,php编写的记录下载的地址,记录下你需要的信息。然后在使用php的 header函数跳转到真正的下载文件地址

<code><?php $file_name = '9567b94e440700226e003fb9258dd733.png';  //下载的文件名
header("Content-Disposition:attachment;filename=".$file_name."");
readfile($file_name);
$header = $_SERVER['HTTP_USER_AGENT'];  //用户UA
$ip = $_SERVER['REMOTE_ADDR'];   //用户IP</code></code>
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn