コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function deliverFile($file, $filename = '', $disposition = self::DISPOSITION_INLINE, $mimeType = null, $cacheDuration = 0)
 {
     $response = new BinaryFileResponse($file);
     $response->setContentDisposition($disposition, $this->sanitizeFilename($filename), $this->sanitizeFilenameFallback($filename));
     $response->setMaxAge($cacheDuration);
     $response->setPrivate();
     if (null !== $mimeType) {
         $response->headers->set('Content-Type', $mimeType);
     }
     return $response;
 }
コード例 #2
0
 protected function serveFile($filename, $displayName, Request $request, $asAttachment = false)
 {
     $lastModified = new \DateTime();
     $lastModified->setTimestamp(filemtime($filename));
     $ifModifiedSince = $request->headers->has('If-Modified-Since') ? new \DateTime($request->headers->get('If-Modified-Since')) : false;
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mimeType = finfo_file($finfo, $filename);
     $response = new BinaryFileResponse($filename);
     $response->setMaxAge(10);
     $response->headers->addCacheControlDirective('must-revalidate');
     $response->headers->set('Content-Type', $mimeType);
     $response->setLastModified($lastModified);
     $response->setContentDisposition($asAttachment ? ResponseHeaderBag::DISPOSITION_ATTACHMENT : ResponseHeaderBag::DISPOSITION_INLINE, $displayName, mb_convert_encoding($displayName, "ASCII", "UTF-8"));
     $response->prepare($request);
     if ($ifModifiedSince && $ifModifiedSince <= $lastModified) {
         $response->setStatusCode(304);
     }
     return $response;
 }