Bonjour à tous,

Je fais du traitement server de fichiers que je zippe et que je souhaite ensuite permettre à l'utilisateur de récupérer sur son PC.

Je me suis inspiré de bonne pratiques trouvées dans d'autres post, mais mon traitement s'arrete à partir du moment où je dé-commente la ligne: header("Content-disposition: attachment; filename=$filepath");

Je ne comprends pas pourquoi.

Auriez-vous une idée ?

Merci pour votre aide.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
<html>
HELLO
<br>
TELECHARGEMENT DU FICHIER
<br>
 
 
<?php
 
 
 
$filepath = 'clients\\fichier.zip';
$filename = basename ($filepath);
 
if (file_exists($filepath)) {
	echo "Download OK";
	echo "<br>";
}
else {
	echo "Download KO";
	echo "<br>";
}
 
 switch(strrchr($filename, ".")) {
 
case ".gz": $type = "application/x-gzip"; break;
case ".tgz": $type = "application/x-gzip"; break;
case ".zip": $type = "application/zip"; echo "zip"; break;
case ".pdf": $type = "application/pdf"; break;
case ".png": $type = "image/png"; break;
case ".gif": $type = "image/gif"; break;
case ".jpg": $type = "image/jpeg"; break;
case ".txt": $type = "text/plain"; break;
case ".htm": $type = "text/html"; break;
case ".html": $type = "text/html"; break;
case ".xml": $type = "text/xml"; break;
default: $type = "application/octet-stream"; break;
 
}
 
 
header("Content-disposition: attachment; filename=$filepath");
/*
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: $type\n");
header("Content-Length: ".filesize($filepath));
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
 
readfile($filepath);
*/
 
 
?>
</html>