Bonjour à tous,

J'ai besoin de créer un script de téléchargement pour mon site, mais je rencontre un soucis.
Le script fonctionne mais le téléchargement se termine à environ 95% de la taille du fichier se qui à donc en conséquence de rendre le fichier corrompu.

Voici mon script :

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 
@ignore_user_abort(false);
error_reporting(E_ALL);
ini_set("display_errors", 1);
// désactivation compression GZip
if (ini_get("zlib.output_compression")) {
	ini_set("zlib.output_compression", 0);
}
 
session_start();
 
$link= new stdClass;
$link->name = 'ubuntu-15.10-desktop-amd64.iso';
$link->size = '1177550848';
$link->link = 'http://releases.ubuntu.com/15.10/ubuntu-15.10-desktop-amd64.iso';
 
$extension = pathinfo($link->name, PATHINFO_EXTENSION);
 
		$newName = $search->slug.'.www.mon-site.com.'.$extension;
 
		switch($extension) {
	        case "pdf":
	            $ctype = "application/pdf";
	            break;
	        case "exe":
	            $ctype = "application/octet-stream";
	            break;
	        case "zip":
	            $ctype = "application/zip";
	            break;
	        case "doc":
	            $ctype = "application/msword";
	            break;
	        case "xls":
	            $ctype = "application/vnd.ms-excel";
	            break;
	        case "ppt":
	            $ctype = "application/vnd.ms-powerpoint";
	            break;
	        case "gif":
	            $ctype = "image/gif";
	            break;
	        case "png":
	            $ctype = "image/png";
	            break;
	        case "jpeg":
	            $ctype = "image/jpg";
	            break;
	        case "jpg":
	            $ctype = "image/jpg";
	            break;
	        case "mp3":
	            $ctype = "audio/mpeg";
	            break;
	        case "wav":
	            $ctype = "audio/x-wav";
	            break;
	        case "mpeg":
	            $ctype = "video/mpeg";
	            break;
	        case "mpg":
	            $ctype = "video/mpeg";
	            break;
	        case "mpe":
	            $ctype = "video/mpeg";
	            break;
	        case "mov":
	            $ctype = "video/quicktime";
	            break;
	        case "avi":
	            $ctype = "video/x-msvideo";
	            break;
	        case "src":
	            $ctype = "plain/text";
	            break;
	        default:
	            $ctype = "application/force-download";
	    }
 
		// fermeture de la session
		session_write_close();
 
		set_time_limit(0);
 
		header("Content-Description: File Transfer");
		header("Content-Type: application/force-download");
		header("Content-Type: application/octet-stream");
		header("Content-Type: application/download");
 
		header('Content-Transfer-Encoding: binary');
		header('Accept-Ranges: bytes');
		header('Content-Disposition: attachment; filename='.$newName);
		header("Cache-control: must-revalidate");
 		header('Pragma: public');
		header("Expires: 0");
		header('Content-Length: ' . $link->size);
		header ("Content-type: " . $ctype);
		header('Connection: close');
 
		ob_end_flush();
 
		$chunksize = 1 * (1024 * 1024); // how many bytes per chunk 
		if ($link->size > $chunksize) { 
		  	$handle = fopen($link->link, 'rb'); 
		  	$buffer = ''; 
		  	while (!feof($handle)) {
		    	$buffer = fread($handle, $chunksize); 
		    	echo $buffer;
		    	flush(); 
		  	} 
		  	fclose($handle);
		  	exit();
		}
Je vous ais mis un lien de téléchargement annexe pour que vous puissiez tester, mais sinon es-ce que quelqu'un aurait une solution pour ce soucis ?

Merci cordialement