I did not edit any files. I'm using this script as file download.php:
<?php
//CONFIGURATION SECTION
$FILES_DIR = "/folder/";
$MYSQL_USER = "user"; //The username used to connect to MySQL
$MYSQL_PASS = "pass"; //The MySQL Password for the user
$MYSQL_HOST = "localhost"; //The host to connect to
$MYSQL_DB = "db"; //The database in which the dl_count table is in
$cnt_sql = @mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS);
@mysql_select_db($MYSQL_DB, $cnt_sql);
if(isset($_GET['file'])) {
$file = urlencode($_GET['file']);
if(empty($file)) {
echo "No File Specified";
exit;
}
if(strpos($file, "..") !== FALSE) {
echo "HACK ATTEMPT!";
exit;
}
if(strpos($file, "://") !== FALSE) {
echo "Invalid File";
exit;
}
$cookie = urlencode(str_replace(".", "_", $file)); //cookie fix
$query = "SELECT * FROM cpg_dl_count WHERE file = '$file'";
$result = mysql_query($query, $cnt_sql);
if(!$result) {
echo mysql_error();
exit;
}
if(mysql_num_rows($result) == 0) {
//first use of this file
$query = "INSERT INTO cpg_dl_count VALUES('$file', 1)";
$result = mysql_query($query, $cnt_sql);
setcookie("dl_" . $cookie, "set", time() + 60*60*24*365);
} else {
if(!isset($_COOKIE['dl_' . $cookie])) {
$query = "UPDATE cpg_dl_count SET count = count + 1 WHERE file = '$file'";
$result = mysql_query($query);
setcookie("dl_". $cookie, "set", time() + 60*60*24*365);
}
}
header("Location: " . $FILES_DIR . $file);
}
function showCount($fileID)
{
global $cnt_sql;
$query = "SELECT count FROM cpg_dl_count WHERE file = '$fileID'";
$result = mysql_query($query, $cnt_sql);
if(mysql_num_rows($result) == 0) {
return 0;
} else {
$count = mysql_fetch_row($result);
return $count[0];
}
}
?>
In the image description field I have links for download created with bbcode that looks like this
download.php?file=testfile.zip When someone click on that download link first time, entry testfile.zip is automatically added to database table cpg_dl_count that I have created. Database table has two columns: filename and count. Every time someone click to download some file count is updated.
In order to display number of downloads in image description filed I have to include download.php script to cpg and show results with this:
<?php echo showCount("testfile.zip"); ?>I don't know how to show this results because I can't use php in image description field.
I have attached original script if someone is interested
You can see this download links in my Themes album at
http://neville.x05host.com