![]() |
[PHP] Download Counter erstellen
Hi !
Ich bin nun schon seit geraumer Zeit auf der Suche nach einem PHP Script, mit dem man auf seiner Homepage anzeigen lassen kann, wie oft eine bestimmte Datei heruntergeladen wurde. Kennt jemand so ein Script, das relativ simpel zu verstehen ist ? Danke ! mfg, Assun |
Re: [PHP] Download Counter erstellen
So geht es bei mir:
Code:
//Download-Zähler
function incprog($id) { //Tabellenabfrage etc ... $count = $result['prog_download_count']; $newcount = $count + 1; $sql_inc = mysql_query("UPDATE pridev_programs SET prog_download_count = '$newcount' WHERE prog_id = $id"); } |
Re: [PHP] Download Counter erstellen
wenn man ganz pervers ist könnte man auch auf die idee kommen, mal bei google danach zu suchen :roll:
![]() dann klickt man das erste ergebnis an, und schon hat man was man sucht |
Re: [PHP] Download Counter erstellen
:shock:
oh, habe vergessen zu erwähnen, dass ich mich in PHP noch sehr wenig auskenne ;-) d.h. ich kapier dein Beispiel irgendwie net :wink: // Edit : Habe nun ein Script gefunden. Beitrag kann gelöscht werden. Danke sehr ! |
Re: [PHP] Download Counter erstellen
Du musst das entweder mit eine Datenbank (MySQL) oder mit Textdateien lösen. Matze hat hier die Lösung mit der Datenbank gepostet:
SQL-Code:
Das ganze machst du in einer Tabelle, die z.B. so aussehen könnte:
UPDATE counter SET dl_count = dl_count+1 WHERE prog = 'dein_programm';
SQL-Code:
Wenn du das ganze jetzt in php machen willst, musst du zuerst eine
CREATE TABLE `counter` (
`prog` VARCHAR( 80 ) NOT NULL , `dl_count` INT DEFAULT '0' NOT NULL , PRIMARY KEY ( `prog` ) ); ![]()
Code:
Das musst du dann entsprechend ausführen, wenn dein Programm heruntergeladen wird. Du musst dann nur noch dafür sorgen, dass der Funktion das richtige Programm übergeben wird. :wink:
//Download-Zähler
function incprog($dein_programm) { //Tabellenabfrage etc ... $count = $result['prog_download_count']; $newcount = $count + 1; $sql_inc = mysql_query("UPDATE counter SET dl_count = dl_count+1 WHERE prog = '$dein_programm'"); } |
Re: [PHP] Download Counter erstellen
und den header("Filetyp: xxx") aufrufen und readfile("datei"),
sonst passiert ja nichts :-) |
Re: [PHP] Download Counter erstellen
Zitat:
|
Re: [PHP] Download Counter erstellen
naja, ansonsten wird der Downloadzähler erhöht, aber die Datei, die gedownloadet werden soll kommt nicht.
![]() EDIT: besonders der Teil (damit kann man einer bestimmte Datei mit php rausschießen...):
Code:
function dl_file($file){
//First, see if the file exists if (!is_file($file)) { die("[b]404 File not found![/b]"); } //Gather relevent info about file $len = filesize($file); $filename = basename($file); $file_extension = strtolower(substr(strrchr($filename,"."),1)); //This will set the Content-Type to the appropriate setting for the file switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; case "mp3": $ctype="audio/mpeg"; break; case "wav": $ctype="audio/x-wav"; break; case "mpeg": case "mpg": case "mpe": $ctype="video/mpeg"; break; case "mov": $ctype="video/quicktime"; break; case "avi": $ctype="video/x-msvideo"; break; //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files) case "php": case "htm": case "html": case "txt": die("[b]Cannot be used for ". $file_extension ." files![/b]"); break; default: $ctype="application/force-download"; } //Begin writing headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); //Use the switch-generated Content-Type header("Content-Type: $ctype"); //Force the download $header="Content-Disposition: attachment; filename=".$filename.";"; header($header ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".$len); @readfile($file); exit; } ?> |
Re: [PHP] Download Counter erstellen
am besten ist es immernoch, die downloads in ein eigenes verzeichnis zu packen, und dann (wichtigst !!!) per
Code:
urldecode ($QUERY_STRING) ==> Dateiname
if ((! is_file ($imagepath)) or (preg_match ("/[\\|\/]/", urldecode ($QUERY_STRING)) != 0)) die ("Fehler: Ungültige Datei
Error: Invalid File"); Schlägt alarm, wenn :arrow: die datei keine ist :arrow: Slashes oder Backslashes im Dateinamen vorkommen Außerdem würde ich die Datei statt mit
Code:
mit diesem Content-Type versehen:
application/force-download
Code:
Der ist nämlich dafür vorgesehen:
application/octet-stream
W3C: The primary subtype, "octet-stream", is to be used in the case of uninterpreted binary data, in which case the simplest recommended action is to offer to write the information into a file for the user. |
Re: [PHP] Download Counter erstellen
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:04 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz