Home > Backend Development > PHP Tutorial > 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?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:19:37
Original
898 people have browsed it

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>
Copy after login

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template