I had a MySQL Download counter previously "working" a few months ago and all of a sudden it has stopped working, It was recording (individual cydia downloads) to the database then posting it to the main webpage with Stats. I've gone through all the code and files, over and over again. Over 24Hours digging and it has still not been solved. If i link the files or post the text "on Here" Would someone please help me.
CONNECT.php
<?php
$server = "localhost";
$user = "root";
$password = "PASSWORD";
$database = mysql_connect ($server, $user, $password);
mysql_select_db("DATABASE_NAME", $database); `
?>
COUNTER.php
<?php
include("connect.php");
$filename = mysql_real_escape_string($_GET['file']);
$path = $_SERVER['DOCUMENT_ROOT']."/";
$fullPath = $path.$filename;
$filetypes = array("deb", "zip");
if (!in_array(substr($filename, -3), $filetypes)) {
echo "Invalid download type.";
exit;
}
if ($fd = fopen ($fullPath, "r")) {
$result = mysql_query("SELECT COUNT(*) AS countfile FROM download
WHERE filename='" . $filename . "'");
$data = mysql_fetch_array($result);
$q = "";
if ($data['countfile'] > 0) {
$q = "UPDATE download SET dldate = NOW()+INTERVAL +6 HOUR, stats = stats + 1 WHERE
filename = '" . $filename . "'";
} else {
$q = "INSERT INTO download (filename, dldate, stats) VALUES
('" . $filename . "',NOW()+INTERVAL +6 HOUR, 1)"; /* +6 = UK Timezone */
}
$statresult = mysql_query($q);
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
header("Cache-control: private");
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>
INDEX.html
<div class="downloads">Downloads:
<?PHP
include("connect.php");
$query = "SELECT stats FROM download WHERE filename = 'deb/com.icon.deb'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo $row[0];
}
?>
</div>
</div>