Bonsoir.
Cela fait quelques jours que je but sur un bout de code pour mon site. Je voudrais proposer en téléchargement des fichiers, sans que le visiteur ne connaisse le répertoire de stockage.
Pour cela, j'utilise donc un fichier get.php qui récupère les infos nécessaires dans l'URL pour fournir le fichier. J'ai droit à quelques warnings de la part des header (Cannot modify header information - headers already sent by...), qui ne sont pas bien graves, mais en plus au lieu de me fournir le fichier, j'ai droit à une page HTML incompréhensible.
Voici le code de mon script get.php :
Et l'allure de mon URL :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php if (isset($_GET['file']) && isset($_GET['type']) && isset($_GET['format'])) // Si le visiteur veut télécharger un fichier { if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) { $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT']; } elseif (!empty($_SERVER['HTTP_USER_AGENT'])) { $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; } $name = htmlentities($_GET['file'], ENT_QUOTES); // sécurisation de la variable $type = htmlentities($_GET['type'], ENT_QUOTES); // sécurisation de la variable $format = htmlentities($_GET['format'], ENT_QUOTES); // sécurisation de la variable if($type == "video") { $file = "downloads/videos/".$name.".".$format; if (eregi('MSIE[[:space:]]+[0-9]+\.[0-9]+', $HTTP_USER_AGENT)) { //if browser is IE compatible header('Content-Type: application/octetstream'); header('Content-Disposition: inline; filename="'.$name.$format.'"'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else { //if browser is not IE compatible header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.$name.$format.'"'); header('Expires: 0'); header('Pragma: no-cache'); } //header("Location : $dir".$name.$format."");*/ readfile($file); } } ?>
Pour info, je suis hébergé chez Free (ça se voit à l'URL ).
Code : Sélectionner tout - Visualiser dans une fenêtre à part http://furankum.free.fr/get.php?file=Stripped&type=video&format=wmv
Merci et bonne soirée
Partager