Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Download.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Downloadable\Helper\Download as DownloadHelper;
10 
17 {
21  private $disallowedContentTypes = [
22  'text/html',
23  ];
24 
32  protected function _processDownload($path, $resourceType)
33  {
34  /* @var $helper DownloadHelper */
35  $helper = $this->_objectManager->get(\Magento\Downloadable\Helper\Download::class);
36 
37  $helper->setResource($path, $resourceType);
38  $fileName = $helper->getFilename();
39 
40  $contentType = $helper->getContentType();
41 
43  $response = $this->getResponse();
44  $response->setHttpResponseCode(
45  200
46  )->setHeader(
47  'Pragma',
48  'public',
49  true
50  )->setHeader(
51  'Cache-Control',
52  'must-revalidate, post-check=0, pre-check=0',
53  true
54  )->setHeader(
55  'Content-type',
56  $contentType,
57  true
58  );
59 
60  if ($fileSize = $helper->getFileSize()) {
61  $response->setHeader('Content-Length', $fileSize);
62  }
63 
64  $contentDisposition = $helper->getContentDisposition();
65  if (!$contentDisposition || in_array($contentType, $this->disallowedContentTypes)) {
66  // For security reasons we force browsers to download the file instead of opening it.
68  }
69 
70  $response->setHeader('Content-Disposition', $contentDisposition . '; filename=' . $fileName);
71  //Rendering
72  $response->clearBody();
73  $response->sendHeaders();
74 
75  $helper->output();
76  }
77 
83  protected function _getLink()
84  {
85  return $this->_objectManager->get(\Magento\Downloadable\Model\Link::class);
86  }
87 }
$response
Definition: 404.php:11
$helper
Definition: iframe.phtml:13
$fileName
Definition: translate.phtml:15