首頁  >  文章  >  後端開發  >  html - 對一個文件進行發送了下載請求,php能記錄下這次請求麼,可以透過什麼來記錄這個請求?

html - 對一個文件進行發送了下載請求,php能記錄下這次請求麼,可以透過什麼來記錄這個請求?

WBOY
WBOY原創
2016-08-04 09:19:37835瀏覽

如題,沒有代碼描述。
或透過設定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>

最簡單的方法:使用者下載檔案先要求,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>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn