gpt4 book ai didi

php - 如何跟踪文件下载

转载 作者:IT老高 更新时间:2023-10-28 11:54:55 25 4
gpt4 key购买 nike

我有一个在 Flash 播放器中播放 mp3 的网站。如果用户单击“播放”,Flash 播放器会自动下载 mp3 并开始播放。

是否有一种简单的方法可以跟踪特定歌曲剪辑(或任何二进制文件)的下载次数?


Is the play link a link to the actual mp3 file or to some javascript code that pops up a player?

If the latter, you can easily add your own logging code in there to track the number of hits to it.

If the former, you'll need something that can track the web server log itself and make that distinction. My hosting plan comes with Webalizer, which does this nicely.

这是一个 javascript 代码,因此可以回答这个问题。

但是,如果知道如何使用其他方法(无需切换主机)来跟踪下载,那就太好了。

最佳答案

有趣的是我在两天前为我所有的音乐写了一个 php 媒体库。我有一个类似的问题。我正在使用 http://musicplayer.sourceforge.net/为玩家。播放列表是通过 php 构建的。所有音乐请求都转到一个名为 xfer.php?file=WHATEVER

的脚本
$filename = base64_url_decode($_REQUEST['file']);
header("Cache-Control: public");
header('Content-disposition: attachment; filename='.basename($filename));
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($filename));

// Put either file counting code here, either a db or static files
//
readfile($filename); //and spit the user the file

function base64_url_decode($input) {
return base64_decode(strtr($input, '-_,', '+/='));
}

当您调用文件时,请使用以下内容:

function base64_url_encode($input) {
return strtr(base64_encode($input), '+/=', '-_,');
}

http://us.php.net/manual/en/function.base64-encode.php

如果您使用需要 mp3 文件或其他文件的实际链接的 JavaScript 或 Flash 播放器(例如 JW 播放器),您可以附加文本“&type=.mp3”,以便最终链接变为:“www.example.com/xfer.php?file=34842ffjfjxfh&type=.mp3”。这样看起来它以 mp3 扩展名结尾而不影响文件链接。

关于php - 如何跟踪文件下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com