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

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

问题描述

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



有没有一种简单的方式来跟踪特定歌曲剪辑(或任何二进制文件)已下载多少次?







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



如果是后者,您可以轻松地添加
自己的日志记录代码来跟踪
的点击次数。 p>

如果是前者,您将需要一些
,可以跟踪Web服务器日志
本身并进行区分。我的
托管计划附带webalizer,
这样做很好。


这是JavaScript代码,所以答案那。



但是,要知道如何使用其他方法(不需要切换主机)来跟踪下载量,这将是非常好的。

解决方案

有趣的是,我在2天前为所有的音乐写了一个php媒体画廊。我也有类似的问题。我使用 http://musicplayer.sourceforge.net/ 播放器。而playlis是通过php建立的。所有的音乐请求都有一个名为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));

//将这里的文件计数代码放在这里。一个数据库或静态文件

//

readfile($ filename); //并吐出用户文件


函数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



如果您使用某些JavaScript或Flash Player(例如JW播放器),需要实际链接为mp3文件或任何内容,则可以附加文本& type = .mp3最终的链接变成www.example.com/xfer.php?file=34842ffjfjxfh&type=.mp3。这样,它看起来像一个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?


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.

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).

解决方案

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), '+/=', '-_,');
}

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

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天全站免登陆