public function stickerAction() { $response = $this->checkAuth(AdminResources::MODULE, TNTFrance::getModuleCode(), AccessManager::UPDATE); if (null !== $response) { return $response; } $tntOrderParcelResponseIdList = $this->getRequest()->request->get("tnt-order-parcel-response"); if ($tntOrderParcelResponseIdList) { $tntOrderParcelResponses = TntOrderParcelResponseQuery::create()->findPks($tntOrderParcelResponseIdList); $event = new TNTFrancePrintExpeditionEvent($tntOrderParcelResponses); $this->dispatch(TNTFranceEvents::TNT_FRANCE_PRINT_EXPEDITION, $event); $zipName = "stickers.zip"; if (file_exists($zipName)) { unlink($zipName); } $zip = new ZipArchive(); if ($zip->open($zipName, ZipArchive::CREATE) === true) { $zip->addEmptyDir('stickers'); foreach ($event->getTntOrderParceResponses() as $tntOrderParcelResponse) { $fileName = $tntOrderParcelResponse->getOrderProductId() . '.pdf'; $filePath = TNTFrance::getUploadDirectory() . $fileName; if (file_exists($filePath)) { $handle = fopen($filePath, 'r'); $contents = fread($handle, filesize($filePath)); fclose($handle); $zip->addFromString('stickers/' . $fileName, $contents); } } $zip->close(); //If no pdf found, zip won't exists if (file_exists($zipName)) { if ($downloadZip = fopen($zipName, "r")) { $zipSize = filesize($zipName); header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=\"" . $zipName . "\""); header("Content-length: {$zipSize}"); header('Content-Transfer-Encoding: binary'); echo fpassthru($downloadZip); // deliver the zip file } fclose($downloadZip); } } } return $this->redirectToDefaultPage(); }