Download aufnehmen/beobachten

Zettt

Doppelter Melonenapfel
Registriert
16.10.05
Beiträge
3.374
Hallo,


Ich habe ein Problem.
Ich moechte gerne den Download einer Datei beobachten. Also vor allem wie oft sie heruntergeladen wurde.

Leider habe ich keine direkte Moeglichkeit ueber ein Statistiktool gefunden. Mein letzter Versuch war das Wordpress Plugin "Wordpress Download Monitor". Aber das funktioniert leider auch nicht.

Weiss jemand vielleicht ein Loesung? Am besten direkt fuer Wordpress...

Danke
 

Maluku

Finkenwerder Herbstprinz
Registriert
10.05.08
Beiträge
464
Wie oft eine Datei heruntergeladen wurde, kann nur dein Webserver zählen, du kannst zählen wie oft der Link angeklickt wurde, wenn du eine Auswerteseite dazwischenhängst.

Du kannst aber ein Script schreiben, dass die Datei zurückliefert, allerdings muss dann dein Webserver immer arbeiten. Ausserdem sollte die Orginal-Datei nicht von außen erreichbar sein. (Entweder in deinem Home, oder geschützt durch z.B. ein .htaccess (default deny from all) geschütztes Verzeichnis.

Perl Code Idee - nicht getestet:
Code:
[COLOR=#a020f0]#!/usr/bin/perl[/COLOR]
[COLOR=#804040][B]use strict[/B][/COLOR];
[COLOR=#804040][B]use warnings[/B][/COLOR];
[COLOR=#804040][B]use [/B][/COLOR]CGI [COLOR=#ff00ff]qw/[/COLOR][COLOR=#ff00ff]header[/COLOR][COLOR=#ff00ff]/[/COLOR];



[COLOR=#804040][B]print[/B][/COLOR] header(-[COLOR=#ff00ff]type[/COLOR]=>[COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]application/octet-stream[/COLOR][COLOR=#ff00ff]"[/COLOR],-[COLOR=#ff00ff]attachment[/COLOR]=>[COLOR=#ff00ff]'[/COLOR][COLOR=#ff00ff]orginaldatei.erweiterung[/COLOR][COLOR=#ff00ff]'[/COLOR]);
[COLOR=#804040][B]open[/B][/COLOR] [COLOR=#008080]FH[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]<[/COLOR][COLOR=#ff00ff]"[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]/pfad/zur/versteckten/orginaldatei.erweiterung[/COLOR][COLOR=#ff00ff]"[/COLOR] [COLOR=#804040][B]or[/B][/COLOR] [COLOR=#804040][B]die[/B][/COLOR] [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]Kann das Orginal nicht oeffnen wegen: [/COLOR][COLOR=#008080]$![/COLOR][COLOR=#ff00ff]"[/COLOR];
[COLOR=#804040][B]binmode[/B][/COLOR] [COLOR=#008080]FH[/COLOR]; 
[COLOR=#804040][B]binmode[/B][/COLOR] [COLOR=#008080]STDOUT[/COLOR];
[COLOR=#0000ff]#Dieser lese/ausgabeteil kann noch performanter werden![/COLOR]
[COLOR=#804040][B]local[/B][/COLOR] [COLOR=#008080]$/[/COLOR];
[COLOR=#804040][B]print[/B][/COLOR] [COLOR=#008080]<FH>[/COLOR];
[COLOR=#804040][B]close[/B][/COLOR] [COLOR=#008080]FH[/COLOR];

[COLOR=#0000ff]#Dateicounter [/COLOR]
[COLOR=#804040][B]use [/B][/COLOR]Fcntl [COLOR=#ff00ff]'[/COLOR][COLOR=#ff00ff]:flock[/COLOR][COLOR=#ff00ff]'[/COLOR];
[COLOR=#804040][B]unless[/B][/COLOR] ([COLOR=#804040][B]open[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]+<[/COLOR][COLOR=#ff00ff]"[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]orginaldatei.counter[/COLOR][COLOR=#ff00ff]"[/COLOR]) {
        [COLOR=#0000ff]#Wir müssen alles in einem Rutch machen, deswegen flock.[/COLOR]
        [COLOR=#804040][B]flock[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR],LOCK_EX; 
        [COLOR=#804040][B]my[/B][/COLOR] [COLOR=#008080]$count[/COLOR]=[COLOR=#008080]<COUNTER>[/COLOR];
        [COLOR=#804040][B]seek[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR],[COLOR=#ff00ff]0[/COLOR],[COLOR=#ff00ff]0[/COLOR];
        [COLOR=#804040][B]print[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR] [COLOR=#008080]$count[/COLOR][COLOR=#ff00ff]+1[/COLOR];
        [COLOR=#804040][B]close[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR];
}
[COLOR=#804040][B]else[/B][/COLOR] {
        [COLOR=#804040][B]open[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]>[/COLOR][COLOR=#ff00ff]"[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]orginaldatei.counter[/COLOR][COLOR=#ff00ff]"[/COLOR];
        [COLOR=#804040][B]print[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR] [COLOR=#ff00ff]1[/COLOR];
        [COLOR=#804040][B]close[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR];
}
__END__
[COLOR=#0000ff]#Datenbankcounter[/COLOR]
[COLOR=#804040][B]use [/B][/COLOR]DBI;
[COLOR=#804040][B]my[/B][/COLOR] [COLOR=#008080]$dbh[/COLOR]=DBI->[COLOR=#804040][B]connect[/B][/COLOR]([COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]....[/COLOR][COLOR=#ff00ff]"[/COLOR]); [COLOR=#0000ff]#Siehe [URL="http://search.cpan.org/%7ETIMB/DBI/DBI.pm"]perldoc DBI[/URL] und [URL="http://search.cpan.org/%7Ecapttofu/DBD-mysql-4.007/lib/DBD/mysql.pm"]perldoc DBD::mysql[/URL][/COLOR]
[COLOR=#008080]$dbh[/COLOR]->[COLOR=#804040][B]do[/B][/COLOR]([COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]UPDATE filecounter SET counter=counter+1[/COLOR][COLOR=#ff00ff]"[/COLOR]); [COLOR=#0000ff]# WHERE file = "orginaldatei.erweiterung"[/COLOR]

[COLOR=#008080]$dbh[/COLOR]->disconnect;
das Skript speicherst du dann als z.B. file.pl in deinem cgi-bin ordner und rufst es auf als cgi-bin/file.pl/orginaldatei.erweiterung (damit die Browser den richtigen Dateinamen zum speichern nehmen).

Ein Problem gibt es da allerdings: bricht der user den download ab, muss das Skript trotzdem die ganze Datei lesen.
 

Zettt

Doppelter Melonenapfel
Registriert
16.10.05
Beiträge
3.374
Danke fuer die beiden Tipps! Der Download Manager tut endlich mal das was er soll. Nur haengt mir das Plugin an die ZIP Datei ein .html an. o_O
Hab mich beim Programmierer aber schon gemeldet, und der hat meinen Kommentar bei sich auf der Seite geloescht. Tolle Wurst!
das Skript speicherst du dann als z.B. file.pl in deinem cgi-bin ordner
Mal ganz ungeachtet des Nachteils den du noch mit anfuehrst. Ich habe gar keinen cgi-bin Ordner. :-[
Aber an so etwas habe ich auch schon gedacht, dass ich mir einfach ein selbst ein Script hacke was genau diese eine Datei quasi verlinkt und den Download mitzaehlt.
 

Zettt

Doppelter Melonenapfel
Registriert
16.10.05
Beiträge
3.374
Ich habe bei Analytics in den Helpfiles eine Anleitung gefunden, wie man Dateien tracken kann. Aber ich werde da nicht schlau draus:
http://www.google.com/support/analytics/bin/answer.py?hl=en-in&answer=55529

Code:
<a href="http://www.example.com/files/map.pdf" onClick="javascript: pageTracker._trackPageview('/downloads/map'); ">

Hinter das href kommt der Link zur Datei. Das ist klar.
Und in die Klammer in trackPageview kann ich doch irgendeinen Phantasienamen eintragen den ich dann spaeter in der Statistik aufgetaucht haben moechte oder?

Wo muss ich da denn nachsehen? Irgendwie klappt das nicht.
 

Maluku

Finkenwerder Herbstprinz
Registriert
10.05.08
Beiträge
464
Das Klappt aber nur, wenn ein User JavaScript aktiviert hat und keiner den Link klaut. Ausserdem muss da glaube ich noch ein Javascript-Teil mit eingebunden werden.
 

Zettt

Doppelter Melonenapfel
Registriert
16.10.05
Beiträge
3.374
Achso. Stimmt auch wieder. Das ist dann natuerlich doof.
Hast du dann eventuell eine andere Idee?
 

mschoening

Gelbe Schleswiger Reinette
Registriert
21.02.07
Beiträge
1.764
Hi,
ich habe da auch noch mal eine Frage dazu, ich weiß zwar wie ich einen Zähler für ein Link baue (PHP) aber kann ich auch tracen wie oft die Datei komplett runter geladen wurde? Es handelt sich um eine ZIP Datei.

Thanks,
Max
 

Maluku

Finkenwerder Herbstprinz
Registriert
10.05.08
Beiträge
464
Das hängt vom Webserver ab:

1. du musst die Datei wie oben von mir beschrieben per Skript "erzeugen", damit du die Kontrolle behälts.
2. Du musst hoffen das der Webserver dein Skript killt, meistens mit einem Signal, vielleicht aber schließt er dem Skript auch nur die Filehandles, dann muss man "close STDOUT" auf rückgabewert überprüfen.

Ungetester Code, ich teste das wenn ich Zeit habe:

Code:
[COLOR=#a020f0]#!/usr/bin/perl[/COLOR]
[COLOR=#804040][B]use strict[/B][/COLOR];
[COLOR=#804040][B]use warnings[/B][/COLOR];
[COLOR=#804040][B]use [/B][/COLOR]CGI [COLOR=#ff00ff]qw/[/COLOR][COLOR=#ff00ff]header request_method[/COLOR][COLOR=#ff00ff]/[/COLOR];

[COLOR=#0000ff]#Signalverwaltung, Signal ist meistens HUP oder TERM[/COLOR]
[COLOR=#008080]$SIG[/COLOR]{HUP} = [COLOR=#008080]$SIG[/COLOR]{ABORT} = [COLOR=#008080]$SIG[/COLOR]{TERM} = [COLOR=#008080]$SIG[/COLOR]{QUIT} =[COLOR=#804040][B]sub[/B][/COLOR]{
        [COLOR=#0000ff]#Hier kann noch vielleicht ein "incomplete" Counter eingebaut werden.[/COLOR]
        [COLOR=#804040][B]exit[/B][/COLOR];
}

[COLOR=#804040][B]my[/B][/COLOR] [COLOR=#008080]$length[/COLOR] = [COLOR=#804040][B]-s[/B][/COLOR] [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]/pfad/zur/versteckten/orginaldatei.erweiterung[/COLOR][COLOR=#ff00ff]"[/COLOR];
[COLOR=#804040][B]print[/B][/COLOR] header(-[COLOR=#ff00ff]type[/COLOR]=>[COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]application/octet-stream[/COLOR][COLOR=#ff00ff]"[/COLOR],-[COLOR=#ff00ff]attachment[/COLOR]=>[COLOR=#ff00ff]'[/COLOR][COLOR=#ff00ff]orginaldatei.erweiterung[/COLOR][COLOR=#ff00ff]'[/COLOR],-[COLOR=#ff00ff]Content_length[/COLOR]=>[COLOR=#008080]$length[/COLOR]);

[COLOR=#0000ff]#Firefox fragt erst einmal mit HEAD nach der Groesse, also koennen wir hier abbrechen:[/COLOR]
[COLOR=#804040][B]exit[/B][/COLOR] [COLOR=#804040][B]if[/B][/COLOR] request_method() [COLOR=#804040][B]eq[/B][/COLOR] [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]HEAD[/COLOR][COLOR=#ff00ff]"[/COLOR];

[COLOR=#804040][B]open[/B][/COLOR] [COLOR=#008080]FH[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]<[/COLOR][COLOR=#ff00ff]"[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]/pfad/zur/versteckten/orginaldatei.erweiterung[/COLOR][COLOR=#ff00ff]"[/COLOR] [COLOR=#804040][B]or[/B][/COLOR] [COLOR=#804040][B]die[/B][/COLOR] [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]Kann das Orginal nicht oeffnen wegen: [/COLOR][COLOR=#008080]$![/COLOR][COLOR=#ff00ff]"[/COLOR];
[COLOR=#804040][B]binmode[/B][/COLOR] [COLOR=#008080]FH[/COLOR]; 
[COLOR=#804040][B]binmode[/B][/COLOR] [COLOR=#008080]STDOUT[/COLOR];
[COLOR=#0000ff]#Dieser lese/ausgabeteil kann noch performanter werden![/COLOR]
[COLOR=#804040][B]local[/B][/COLOR] [COLOR=#008080]$/[/COLOR];
[COLOR=#804040][B]print[/B][/COLOR] [COLOR=#008080]<FH>[/COLOR];
[COLOR=#804040][B]close[/B][/COLOR] [COLOR=#008080]FH[/COLOR];

[COLOR=#0000ff]#Dateicounter [/COLOR]
[COLOR=#804040][B]use [/B][/COLOR]Fcntl [COLOR=#ff00ff]'[/COLOR][COLOR=#ff00ff]:flock[/COLOR][COLOR=#ff00ff]'[/COLOR];
[COLOR=#804040][B]unless[/B][/COLOR] ([COLOR=#804040][B]open[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]+<[/COLOR][COLOR=#ff00ff]"[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]orginaldatei.counter[/COLOR][COLOR=#ff00ff]"[/COLOR]) {
        [COLOR=#0000ff]#Wir müssen alles in einem Rutch machen, deswegen flock.[/COLOR]
        [COLOR=#804040][B]flock[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR],LOCK_EX; 
        [COLOR=#804040][B]my[/B][/COLOR] [COLOR=#008080]$count[/COLOR]=[COLOR=#008080]<COUNTER>[/COLOR];
        [COLOR=#804040][B]seek[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR],[COLOR=#ff00ff]0[/COLOR],[COLOR=#ff00ff]0[/COLOR];
        [COLOR=#804040][B]print[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR] [COLOR=#008080]$count[/COLOR][COLOR=#ff00ff]+1[/COLOR];
        [COLOR=#804040][B]close[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR];
}
[COLOR=#804040][B]else[/B][/COLOR] {
        [COLOR=#804040][B]open[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]>[/COLOR][COLOR=#ff00ff]"[/COLOR], [COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]orginaldatei.counter[/COLOR][COLOR=#ff00ff]"[/COLOR];
        [COLOR=#804040][B]print[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR] [COLOR=#ff00ff]1[/COLOR];
        [COLOR=#804040][B]close[/B][/COLOR] [COLOR=#008080]COUNTER[/COLOR];
}
[COLOR=#0000ff]__END__[/COLOR]
[COLOR=#0000ff]#Datenbankcounter[/COLOR]
[COLOR=#804040][B]use [/B][/COLOR]DBI;
[COLOR=#804040][B]my[/B][/COLOR] [COLOR=#008080]$dbh[/COLOR]=DBI->[COLOR=#804040][B]connect[/B][/COLOR]([COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]....[/COLOR][COLOR=#ff00ff]"[/COLOR]); [COLOR=#0000ff]#Siehe perldoc DBI und perldoc DBD::mysql[/COLOR]
[COLOR=#008080]$dbh[/COLOR]->[COLOR=#804040][B]do[/B][/COLOR]([COLOR=#ff00ff]"[/COLOR][COLOR=#ff00ff]UPDATE filecounter SET counter=counter+1[/COLOR][COLOR=#ff00ff]"[/COLOR]); [COLOR=#0000ff]# WHERE file = "orginaldatei.erweiterung"[/COLOR]

[COLOR=#008080]$dbh[/COLOR]->disconnect;
 

Maluku

Finkenwerder Herbstprinz
Registriert
10.05.08
Beiträge
464
Von PHP hab ich ehrlich gesagt keine Ahnung....
Müsste aber ähnlich gehen.