@@ -174,7 +174,7 @@ public function postHandler($query, $request, $files)
174174 public function getHandler ($ queries )
175175 {
176176 $ t = $ this ->translate ;
177-
177+
178178 switch ($ queries ['action ' ]) {
179179 case 'download ' :
180180 $ downloaded = $ this ->downloadAction ($ queries ['path ' ]);
@@ -185,7 +185,17 @@ public function getHandler($queries)
185185 }
186186
187187 break ;
188-
188+
189+ case 'downloadMultiple ' :
190+ $ downloaded = $ this ->downloadMultipleAction ($ queries ['items ' ], $ queries ['toFilename ' ]);
191+ if ($ downloaded === true ) {
192+ exit ;
193+ } else {
194+ $ response = $ this ->simpleErrorResponse ($ t ->file_not_found );
195+ }
196+
197+ break ;
198+
189199 default :
190200 $ response = $ this ->simpleErrorResponse ($ t ->function_not_implemented );
191201 break ;
@@ -221,6 +231,34 @@ private function downloadAction($path)
221231 return true ;
222232 }
223233
234+ private function downloadMultipleAction ($ items , $ archiveName )
235+ {
236+ $ archivePath = tempnam ('../ ' , 'archive ' );
237+
238+ $ zip = new \ZipArchive ();
239+ if ($ zip ->open ($ archivePath , \ZipArchive::CREATE ) !== true ) {
240+ unlink ($ archivePath );
241+ return false ;
242+ }
243+
244+ foreach ($ items as $ path ) {
245+ $ zip ->addFile ($ this ->basePath . $ path , basename ($ path ));
246+ }
247+
248+ $ zip ->close ();
249+
250+ header ("Content-Disposition: attachment; filename= \"$ archiveName \"" );
251+ header ('Cache-Control: must-revalidate, post-check=0, pre-check=0 ' );
252+ header ("Content-Type: application/zip " );
253+ header ('Pragma: public ' );
254+ header ('Content-Length: ' . filesize ($ archivePath ));
255+ readfile ($ archivePath );
256+
257+ unlink ($ archivePath );
258+
259+ return true ;
260+ }
261+
224262 private function uploadAction ($ path , $ files )
225263 {
226264 $ path = $ this ->basePath . $ path ;
@@ -390,8 +428,8 @@ private function compressAction($paths, $destination, $archiveName)
390428 {
391429 $ archivePath = $ this ->basePath . $ destination . $ archiveName ;
392430
393- $ zip = new ZipArchive ();
394- if ($ zip ->open ($ archivePath , ZipArchive::CREATE ) !== true ) {
431+ $ zip = new \ ZipArchive ();
432+ if ($ zip ->open ($ archivePath , \ ZipArchive::CREATE ) !== true ) {
395433 return false ;
396434 }
397435
@@ -407,7 +445,7 @@ private function extractAction($destination, $archivePath, $folderName)
407445 $ archivePath = $ this ->basePath . $ archivePath ;
408446 $ folderPath = $ this ->basePath . rtrim ($ destination , '/ ' ) . '/ ' . $ folderName ;
409447
410- $ zip = new ZipArchive ;
448+ $ zip = new \ ZipArchive ;
411449 if ($ zip ->open ($ archivePath ) === false ) {
412450 return 'unsupported ' ;
413451 }
0 commit comments