1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<?php
require('connexion.php');
//Liste des documents.
$documents = array();
$rep = opendir("./pdf");
while ($fichier = readdir($rep)){
if($fichier != "." && $fichier != ".."){
$documents[] = $fichier;
}
}
closedir($rep);
//TTT du formulaire si $_POST n'est pas vide.
if(!empty($_POST)){
//Récupérer le n° du document : prendre la clé de la première ligne de $_POST, normalement du type n_x
//n étant le n° du document.
list($numéro) = each($_POST);
//Convertir la chaîne en entier, seul le n° reste.
$numéro = (integer) $numéro;
//En déduire le nom du document.
$nomFichier = $documents[$numéro];
//Le chemin.
$path = "./pdf/";
//Sa taille.
$poids = filesize($path.$nomFichier);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/pdf\n");
$header="Content-Disposition: attachment; filename=".$nomFichier;
header($header);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$poids);
@readfile($path.$nomFichier);
exit();
}
?>
<form name="telechargements" method="post" action="telechargements.php">
<table cellspacing="0">
<tr><th colspan="2">Visualiser</th><th>Télécharger</th></tr>
<?php
foreach($documents as $numéro => $document){ ?>
echo sprintf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",
"<a href='./pdf/". $document ."' alt='Document PDF'><img src='./image/hand.right.png' /></a>",
"<a href='./pdf/". $document ."' alt='Document PDF'>".chaineTelechargement($document)." /></a>",
"<input type='image' name='$numéro' alt='Télécharger' src='./image/hand.up.png'>");
<?php }
?>
</table>
</form> |
Partager