Home  >  Article  >  Backend Development  >  html - A download request is sent to a file. Can PHP record this request? What can be used to record this request?

html - A download request is sent to a file. Can PHP record this request? What can be used to record this request?

WBOY
WBOYOriginal
2016-08-04 09:19:37833browse

As the title says, there is no code description.
Or how to record this request by configuring apache

Reply content:

As the title says, there is no code description.
Or how to record this request by configuring 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>

The simplest method: the user downloads the file and requests it first, and records the download address written in PHP and records the information you need. Then use the header function of php to jump to the real download file address

<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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn