Provides various official and user-released code examples. For code reference, you are welcome to share and learn the code for calculating the number of file downloads. The main principle is to click download at the front-end. input parameter id in php to update the number of clicks.
Download. php
$ Id = (int) $ _ GET ['id'];
If (! Isset ($ id) | $ id = 0)
Die ('parameter error! ');
$ Query = mysql_query ("select * from downloads where id = '$ id '");
$ Row = mysql_fetch_array ($ query );
If (! $ Row)
Exit;
$ Filename = iconv ('utf-8', 'gbk', $ row ['filename']); // specify the conversion encoding for the Chinese name.
$ Savename = $ row ['savename']; // The name actually saved on the server
$ Myfile = 'files/'. $ savename; // File
If (file_exists ($ myfile )){
Mysql_query ("update downloads set downloads = downloads + 1 where id = '$ id '");
$ File = @ fopen ($ myfile, "r ");
Header ("Content-type: application/octet-stream ");
Header ("Content-Disposition: attachment; filename =". $ filename );
While (! Feof ($ file )){
Echo fread ($ file, 50000 );
}
Fclose ($ file );
Exit;
} Else {
Echo 'file does not exist! ';
}
PHP statistics download times demo: Http://www.sucaihuo.com/php/224.html
Php?mysql=jquerystatistical file download times. Zip (5.96 KB download: 47 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB