OKie getting further with the code. But the hits are not increasing and when downloading in links browser on Linux i get the download page instead of the filename i am downloading when i choose "save as" (works properly in mozilla firefox).
index.php (where the files are listed):
<?php
// mysql conn info
include "db.inc.php";
// run query
$query = "select id,name,size,md5,hit from table order by id";
// get results
if($result = mysql_db_query($db_name, $query, $conn)) {
// loop through results
while($row = mysql_fetch_array($result)) {
echo "<br /><table width='75%' cellpadding='4' cellspacing='1' bgcolor='#000000'>";
echo "<tr>";
echo "<td bgcolor='#FFFFFF'><a href=\"dl.php?id=".$row["id"]."\">".$row["name"]."</a> Size: ".$row["size"]." MD5: ".$row["md5"]." Downloads: ".$row["hit"]."</td>";
echo "</tr>";
echo "</table>";
}
}
?>
dl.php code:
<?php
// mysql conn info
include "db.inc.php";
$id = $_GET["id"];
// setup the query
$query = "select file, path from table where id = $id";
// get results
if($result = mysql_db_query($db_name, $query, $conn)) {
// if we have results
if($row = mysql_fetch_array($result)) {
// get filename and path
$file = $row["file"];
$path = $row["path"];
$hit = $row['hit']+1;
$sql = "UPDATE table SET hit='$hit' WHERE id='$id'";
if ($result = mysql_query($sql)) {
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$file");
header("Content-transfer-encoding: binary\n");
header("Content-length: " . filesize($path.$file) . "\n");
}
$fp=fopen($path.$file, "r");
fpassthru($fp);
}
}
// close db connection
mysql_close($conn);
?>
Now when i don't include
$id = $_GET["id"];
dl.php is blank when hitting the download link but when the _GET is used it works.
Also noticed in the httpd log:
PHP Notice: Undefined index: hit in dl.php on line 18
Where am i going wrong in the code? what else can i include or modify to get it right?
Thanks again for your help!