Solution simple :
- Une table SQL qui contient comme champs : id (clef primaire), nom_fichier (le nom du fichier sur ton serveur), compteur (le compteur de click)
- Lorsque tu affiches le fichier à télécharger tu fais un lien du genre : download.php?id=xx (xx = un entier, qui correspondra à une entrée dans ta table SQL)
- Dans ton fichier download.php :
<?php
// Récupération de l'ID
$id = (isset($_GET['id'])) ? intval($_GET['id']) : NULL;
if (is_null($id))
{
die('Erreur ...');
}
// Vérification de l'existance du fichier, récupération de ses informations
$sql = 'SELECT nom_fichier
FROM ta_table_sql
WHERE id = ' . $id;
$result = mysql_query($sql) OR die(mysql_error());
if (!$row = mysql_fetch_assoc($result))
{
die('Fichier inexistant');
}
mysql_free_result($result);
// Compteur
$sql = 'UPDATE ta_table_sql
SET compteur = compteur + 1
WHERE id = ' . $id;
mysql_query($sql) OR die(mysql_error());
// Lancement du download
$filename = 'chemin/vers/fichier/' . $row['nom_fichier'];
header('Content-Type: application/octetstream; name: ' . $row['nom_fichier']);
header('Content-Disposition: inline; filename="' . $row['nom_fichier'] . '"');
echo file_get_contents($filename);
ob_end_flush();
exit
?>