@@ -64,7 +64,6 @@ private function receiveData($ch, $data) {
64
64
* @return void
65
65
*/
66
66
public function __construct ($ url , $ file = false ) {
67
- set_time_limit (15 );
68
67
ob_start ();
69
68
70
69
$ this ->info = new Data \ZipInfo ();
@@ -82,12 +81,19 @@ public function init() {
82
81
$ request = $ this ->httpRequest (array (
83
82
CURLOPT_URL => $ this ->info ->url ,
84
83
CURLOPT_FOLLOWLOCATION => true ,
85
- CURLOPT_NOBODY => true
84
+ CURLOPT_NOBODY => true ,
85
+ CURLOPT_HEADER => true ,
86
+ CURLOPT_RETURNTRANSFER => true
86
87
));
87
88
88
89
if ($ request ['http_code ' ] > 400 ) {
89
90
user_error (sprintf ('Initial request failed, got HTTP status code: %d ' , $ request ['http_code ' ]) , E_USER_ERROR );
90
- die;
91
+ exit ;
92
+ }
93
+
94
+ if (!$ request ['headers ' ]['Accept-Ranges ' ]) {
95
+ user_error ('Server does not support HTTP range requests ' , E_USER_ERROR );
96
+ exit ;
91
97
}
92
98
93
99
$ this ->info ->length = intval ($ request ['download_content_length ' ]);
@@ -113,7 +119,7 @@ public function init() {
113
119
$ this ->info ->centralDirectoryDesc = new Data \EOCD ($ _EOCD );
114
120
} else {
115
121
user_error ('End of central directory not found ' , E_USER_ERROR );
116
- die ;
122
+ exit ;
117
123
}
118
124
119
125
if ($ cdEnd = $ this ->info ->centralDirectoryDesc ) {
@@ -230,6 +236,7 @@ public function get(Data\CDFile $file, $output = false) {
230
236
));
231
237
232
238
if ($ output ) {
239
+ ob_clean (); # clean output
233
240
header (sprintf ('Content-Disposition: attachment; filename="%s" ' , $ file ->filename ));
234
241
header (sprintf ('Content-Length: %d ' , $ file ->size ));
235
242
header ('Pragma: public ' );
@@ -254,6 +261,17 @@ protected function httpRequest($conf) {
254
261
$ out = curl_exec ($ ch );
255
262
256
263
$ info = curl_getinfo ($ ch );
264
+
265
+ if ($ conf [CURLOPT_HEADER ] && preg_match_all ('/(.*): (.*)\r?\n/ ' , $ out , $ match )) {
266
+ $ _headers = substr ($ out , 0 , $ info ['header_size ' ]);
267
+ $ headers = array ();
268
+ foreach ($ match [1 ] as $ i => $ header ) {
269
+ $ headers [$ header ] = $ match [2 ][$ i ];
270
+ }
271
+ $ info ['headers ' ] = $ headers ;
272
+ $ out = substr ($ out , $ info ['header_size ' ]);
273
+ }
274
+
257
275
$ info ['response ' ] = $ out ;
258
276
259
277
curl_close ($ ch );
0 commit comments