< SCRIPT LANGUAGE="php"> ///////////////////////////////////////////////////////////////////////////// //// COMPTEUR DE TELECHARGEMENTS //// //// <15/10/99 Version 1.00> //// //// (c) //// ///////////////////////////////////////////////////////////////////////////// //// ParamŠtre en entr‚e : $Fichier : nom du fichier … t‚l‚charger (doit ) //// obligatoirement ˆtre dans le mˆme //// r‚pertoire que le script. http://loiseaudor.fr/pdf_gratuit/download.php3?Fichier=mozart_danse_allemande.pdf //// Appel du script : //// Fichier Compteur = $Fichier+.dat; ///////////////////////////////////////////////////////////////////////////// $FileCompteur=$Fichier.".dat"; ///------Fonctions Lock et Unlock d'aprŠs Etienne De Toqueville-------------- Function lock($file) { $timeout = 30; // Timeout (secondes) PHP $retry = 5; // Temps maxi (secondes) d'attente avant abandon $delay = 0.1; // Durée d'attente (secondes) entre chaque test if (file_exists($file.".lck")) { $time = @filemtime($file.".lck"); if ($time) { $since = time() - $time; if ($since > $timeout) unlink($file.".lck"); } } for($i = 0; $i < $retry; $i += $delay) { if (!file_exists($file.".lck")) { $idlck=fopen($file.".lck","w"); fclose($idlck); return 1; } usleep($delay * 1000000); } return 0; } ///------------------------------------------------------------------------- Function unlock($file) { $i = @unlink($file.".lck"); return $i; } ///------------------------------------------------------------------------- Function Error($Msg){ Echo $Msg; FinPres(); Exit(""); } ///------------------------------------------------------------------------- if (!file_exists($FileCompteur)){ $Compteur=1; $Fp=fopen($FileCompteur,"w"); fputs($Fp,$Compteur); fclose($Fp); } else{ if (!lock($FileCompteur)) Error("Occupé ! Recommencez plus tard. Merci."); $Fp=fopen($FileCompteur,"r"); $Compteur=bcadd(Trim(fgets($Fp,255)),"1",0); fclose($Fp); $Fp=fopen($FileCompteur,"w"); fputs($Fp,$Compteur); fclose($Fp); unlock($FileCompteur); } Header("Location: http://www.loiseaudor.fr/pdfs/".$Fichier); Exit(""); ?>