1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?php
$servername = "http://blabla";
$paths = [
'guide_tarifaire_res' => "/path/to/something",
'guide_tarifaire_pro' => "/path/to/something"
];
if (isset($_GET['docname'], $paths[$_GET['docname']])) {
$path = $servername.$paths[$_GET['docname']];
$pdfname = $_GET["docname"].".pdf";
$pdf = file_get_contents($path); // t'es sûr que ton fichier existe au moins ?
$len = strlen($pdf);
header("Content-type: application/pdf");
header("Content-Length: {$len}");
header("Content-Disposition: inline; filename={$pdfname}");
echo $pdf;
} else {
header("location: http://www.exemple.com");
exit; // toujours mettre un exit; après un header(location:)
}
// ne jamais fermer la balise <?php quand un fichier ne contient que du code PHP |