Browse Source

Ch. 4: Streaming files.

Frederic G. MARAND 6 years ago
parent
commit
b670c21f68
1 changed files with 29 additions and 0 deletions
  1. 29 0
      src/Controller/StreamingController.php

+ 29 - 0
src/Controller/StreamingController.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Controller;
+
+
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\HttpFoundation\ResponseHeaderBag;
+use Symfony\Component\Routing\Annotation\Route;
+
+class StreamingController extends AbstractController {
+
+  /**
+   * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
+   *
+   * @Route(
+   *   name = "pass",
+   *   path = "/pass"
+   * )
+   */
+  public function pass() {
+    $response = $this->file('/etc/passwd', 'blougou', ResponseHeaderBag::DISPOSITION_INLINE);
+
+    // Defaults to 'attachment; filename="${basename($file)}"'. When not using
+    // the 2nd and 3rd arguments:
+    // $response->headers->set('Content-disposition', 'inline');
+
+    return $response;
+  }
+}