Bonjour,

j'utilise un code qui force un téléchargement : ce code marche bien si je ne mets rien avant, mais j'ai plein de warnings si je mets du code avant : comment faire cohabiter les deux ?

code qui force le téléchargement :

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
<?php
// code pour forcer un téléchargement
$full_path = 'guide-pose-mod-le.pdf'; // chemin système (local) vers le fichier
$file_name = basename($full_path);
 
ini_set('zlib.output_compression', 0);
$date = gmdate(DATE_RFC1123);
 
header('Pragma: public');
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
 
header('Content-Tranfer-Encoding: none');
header('Content-Length: '.filesize($full_path));
header('Content-MD5: '.base64_encode(md5_file($full_path)));
header('Content-Type: application/octetstream; name="'.$file_name.'"');
header('Content-Disposition: attachment; filename="'.$file_name.'"');
 
header('Date: '.$date);
header('Expires: '.gmdate(DATE_RFC1123, time()+1));
header('Last-Modified: '.gmdate(DATE_RFC1123, filemtime($full_path)));
 
readfile($full_path);
exit; // nécessaire pour être certain de ne pas envoyer de fichier corrompu
 
 
 ?>
Code complet :
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
// code pour incrementer un compteur
 include_once("connect.php"); include_once("config.php"); 
$id_conn = connect(); 
$sql="UPDATE `guide-pose-mod-le` SET compteur = compteur +1;"; 
$result = mysql_query($sql)or die(mysql_error());
close($id_conn);
 
 
// puis code pour forcer un téléchargement
$full_path = 'guide-pose-mod-le.pdf'; // chemin système (local) vers le fichier
$file_name = basename($full_path);
 
ini_set('zlib.output_compression', 0);
$date = gmdate(DATE_RFC1123);
 
header('Pragma: public');
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
 
header('Content-Tranfer-Encoding: none');
header('Content-Length: '.filesize($full_path));
header('Content-MD5: '.base64_encode(md5_file($full_path)));
header('Content-Type: application/octetstream; name="'.$file_name.'"');
header('Content-Disposition: attachment; filename="'.$file_name.'"');
 
header('Date: '.$date);
header('Expires: '.gmdate(DATE_RFC1123, time()+1));
header('Last-Modified: '.gmdate(DATE_RFC1123, filemtime($full_path)));
 
readfile($full_path);
exit; // nécessaire pour être certain de ne pas envoyer de fichier corrompu
Les warnings :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
Warning: Cannot modify header information - headers already sent by (output started at /mnt/163/sda/2/6/laurentschmitt18/test/connect.php:5) in /mnt/163/sda/2/6/laurentschmitt18/test/telecharger_guide-pose-mod-le.php on line 18
 
Warning: Cannot modify header information - headers already sent by (output started at /mnt/163/sda/2/6/laurentschmitt18/test/connect.php:5) in /mnt/163/sda/2/6/laurentschmitt18/test/telecharger_guide-pose-mod-le.php on line 19
...
puis des codes caballistiques :
%PDF-1.4 %âãÏÓ 3588 0 obj << /Linearized 1 /O 3591 /H [ 3051 400 ] /L 4153774 /E 203553 /N 18 /T 4081894 >> endobj xref 3588 125 0000000016 00000 n 0000002856 00000 n 0000002994 00000 n 0000003451 00000 n 0000004196 00000 n 0000004475 00000 n 0000004700 00000 n 0000004926 00000 n 0000005152 00000 n 0000005378 00000 n 0000005615 00000 n 0000005853 00000 n 0000006091 00000 n 0000006329 00000 n 0000006566 00000 n 0000006805 00000 n 0000007044 00000 n 0000007283 00000 n 0000007521 00000 n 0000007760 00000 n 0000007999 00000 n 0000008238 00000 n 0000008476 00000 n 0000008715 00000 n 0000008954 00000 n 0000009193 00000 n 0000009431 00000 n 0000009670 00000 n 0000009909 00000 n 0000010148 00000 n 0000010385 00000 n 0000010623 00000 n 0000010861 00000 n 0000011099 00000 n 0000011207 00000 n 0000011237 00000 n 0000011744 00000 n 0000011767 00000 n 0000011975 00000 n 0000011999 00000 n 0000012036 00000 n 0000018607 00000 n 0000018631 00000 n 0000018668 00000 n ...