如何跟踪文件下载 [英] How do I track file downloads

查看:26
本文介绍了如何跟踪文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a website that plays mp3s in a flash player. If a user clicks 'play' the flash player automatically downloads an mp3 and starts playing it.

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

Is there an easy way to track how many times a particular song clip (or any binary file) has been downloaded?

播放链接是否为实际链接mp3 文件或一些 javascript 代码弹出一个播放器?

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.

如果是前者,你需要一些东西可以跟踪网络服务器日志本身并做出这种区分.我的托管计划附带 Webalizer,这很好.

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 代码,因此可以回答这个问题.

It's a javascript code so that answers that.

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

However, it would be nice to know how to track downloads using the other method (without switching hosts).

推荐答案

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

The funny thing is I wrote a php media gallery for all my musics 2 days ago. I had a similar problem. I'm using http://musicplayer.sourceforge.net/ for the player. And the playlist is built via php. All music requests go to a script called 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, '-_,', '+/='));
}

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

And when you call files use something like:

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 扩展名结尾,而不会影响文件链接.

If you are using some JavaScript or a flash player (JW player for example) that requires the actual link of an mp3 file or whatever, you can append the text "&type=.mp3" so the final link becomes something like: "www.example.com/xfer.php?file=34842ffjfjxfh&type=.mp3". That way it looks like it ends with an mp3 extension without affecting the file link.

这篇关于如何跟踪文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆