public function ArchiveDownloaderController::downloadArchive in Content Synchronizer 8.2
Same name and namespace in other branches
- 8 src/Controller/ArchiveDownloaderController.php \Drupal\content_synchronizer\Controller\ArchiveDownloaderController::downloadArchive()
- 3.x src/Controller/ArchiveDownloaderController.php \Drupal\content_synchronizer\Controller\ArchiveDownloaderController::downloadArchive()
Download the tmp file.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request.
Return value
\Symfony\Component\HttpFoundation\Response The download response.
1 string reference to 'ArchiveDownloaderController::downloadArchive'
File
- src/
Controller/ ArchiveDownloaderController.php, line 28
Class
- ArchiveDownloaderController
- Class ArchiveDownloaderController.
Namespace
Drupal\content_synchronizer\ControllerCode
public function downloadArchive(Request $request) {
if ($request->query
->has(ArchiveDownloader::ARCHIVE_PARAMS)) {
$fileUri = ExportEntityWriter::GENERATOR_DIR . $request->query
->get(ArchiveDownloader::ARCHIVE_PARAMS);
if (file_exists($fileUri)) {
$response = new Response(file_get_contents($fileUri));
$disposition = $response->headers
->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, basename($fileUri));
$response->headers
->set('Content-Disposition', $disposition);
// Delete temporary file.
$repName = substr($fileUri, 0, strrpos($fileUri, '/'));
/** @var \Drupal\Core\File\FileSystemInterface $fileSystem */
$fileSystem = \Drupal::service('file_system');
$fileSystem
->deleteRecursive($repName);
return $response;
}
}
}