Link to home
Start Free TrialLog in
Avatar of oferweisglass
oferweisglass

asked on

file downloads counter

Need to build counter to file downloads

the file is on hosting server and it should be page to download the file (save as)

any ideas?
Avatar of glcummins
glcummins
Flag of United States of America image

You should run all of your files through a download script, rather than via direct links. For example, instead of:

<a href="/files/myfile.zip">Download file here</a>

you can use:

<a href="/download.php?file=myfile.zip">Download file here</a>

Then, the file 'download.php' would contain something like:

<?php
$filename = $_GET['file'];

$result = mysql_query("SELECT downloads FROM table_files WHERE filename='{$filename}'";

$downloads = $results[0];

// Increment the count
$downloads++;

// Upload the new count in to the database
mysql_query("UPDATE files_table SET download='{$downloads}' WHERE filename='{$filename}'");

// Now, redirect to the file
header("Location: /files/$filename");
?>

You would want some more error checking, but this is the basic idea.
Avatar of oferweisglass
oferweisglass

ASKER

how many tables should be in the database? and what fields?
ASKER CERTIFIED SOLUTION
Avatar of glcummins
glcummins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial