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

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

问题描述

我有一个网站,播放MP3的Flash播放器。如果用户点击播放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 code
  弹出一个播放器?

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

如果是后者,你可以轻松地添加您
  在有自己的日志code跟踪
  点击数吧。

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的code,这样回答说。

It's javascript code, so that answers that.

不过,这将是很好知道如何使用另一种方法(无需切换主机)来跟踪下载。

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

推荐答案

有趣的是我3天前写给我的所有的音乐一个PHP媒体库。我有一个类似的问题。即时通讯使用 http://musicplayer.sourceforge.net/ 的球员。和playlis通过PHP的了。所有的音乐要求去那里一个叫做xfer.php脚本?文件= WHATEVER

The funny thing is i wrote a php media gallery for all my music 2 days ago. I had a similar problem. Im using http://musicplayer.sourceforge.net/ for the player. and the playlis are built via php. all music request go there a script called xfer.php?file=WHATEVER

$filename = base64_url_decode($_REQUEST['file']);
header("Cache-Control: public");
header("Content-Description: File Transfer");
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), '+/=', '-_,');
}

<一个href=\"http://us.php.net/manual/en/function.base64-en$c$c.php\">http://us.php.net/manual/en/function.base64-en$c$c.php

如果您使用的是一些JavaScript还是需要实际的链接是一个mp3文件或什么的,你可以追加文本的flash播放器(JW播放器为例)与&amp;类型= .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 to be an mp3 file or whatever, you can append the text "&type=.mp3" so the final linke 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天全站免登陆