On peut le faire avec un array PHP (tableau). Je te prépare un exemple....
alors...
<?php
$tableau = array('fichier1.txt','fichier2.txt','fichier3.txt');
/*
Voici comment le tableau $tableau est indexé
Array
(
[0] => fichier1.txt
[1] => fichier2.txt
[2] => fichier3.txt
)
*/
if (isset($_GET['fichier'])){ // si l'utilisateur a cliqué sur le lien
if (array_key_exists($_GET['fichier'],$tableau)){ // si la clé du fichier existe dans $tableau (voir index ci dessus)
$cle_du_tableau = $_GET['fichier']; // stocke la clé dans une variable (pour que tu comprennes mieux)
/*
http://www.phpfrance.com/forums/voir_sujet-7700.php
Forcer le téléchargement d'un fichier
*/
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($tableau[$cle_du_tableau]) );
header('Accept-Ranges: bytes');
header('Content-Length: '.filesize($tableau[$cle_du_tableau]) );
readfile($filename);
}
else // Affiche une alerte javascript dans le cas où le fichier demandé n'existe pas (clé introuvable dans le tableau)
{
echo "<script language='JavaScript'>window.alert('Fichier inexistant !');</script>"; // le choix de l'affichage
// est libre (en fonction de
// ton gout)
}
}
?>
<html>
<body>
<a href='<?php echo $_SERVER['PHP_SELF'];?>?fichier=0'>Télécharger le fichier 1</a><br/>
<a href='<?php echo $_SERVER['PHP_SELF'];?>?fichier=1'>Télécharger le fichier 2</a><br/>
<a href='<?php echo $_SERVER['PHP_SELF'];?>?fichier=2'>Télécharger le fichier 3</a><br/>
<a href='<?php echo $_SERVER['PHP_SELF'];?>?fichier=3'>Télécharger un fichier qui n'existe pas</a><br/>
</body>
</html>
Tu peux également utiliser une table MySQL, SQLite, ou n'importe quel type de base de donnée (pour une gestion plus souple des fichiers à télécharger... préférable à la méthode des array si tu as des centaines de fichiers)
Si tu n'as pas compris quelque chose, nous sommes à ton écoute
