121 \
Magento\Downloadable\Helper\
File $downloadableFile,
122 \
Magento\MediaStorage\Helper\
File\Storage\Database $coreFileStorageDb,
127 parent::__construct($context);
128 $this->_downloadableFile = $downloadableFile;
129 $this->_coreFileStorageDb = $coreFileStorageDb;
143 if (!$this->_resourceFile) {
144 throw new CoreException(
__(
'Please set resource file and link type.'));
147 if ($this->_handle ===
null) {
148 if ($this->_linkType == self::LINK_TYPE_URL) {
150 $protocol = strtolower(parse_url(
$path, PHP_URL_SCHEME));
155 $this->_handle = $this->fileReadFactory->create(
$path, $protocol);
156 }
elseif ($this->_linkType == self::LINK_TYPE_FILE) {
158 $fileExists = $this->_downloadableFile->ensureFileInFilesystem($this->_resourceFile);
160 $this->_handle = $this->_workingDirectory->openFile($this->_resourceFile);
162 throw new CoreException(
__(
'Invalid download link type.'));
165 throw new CoreException(
__(
'Invalid download link type.'));
178 return $this->
_getHandle()->stat($this->_resourceFile)[
'size'];
189 if ($this->_linkType == self::LINK_TYPE_FILE) {
193 $this->_workingDirectory->getAbsolutePath($this->_resourceFile)
198 return $this->_downloadableFile->getFileType($this->_resourceFile);
200 }
elseif ($this->_linkType == self::LINK_TYPE_URL) {
201 return $this->_handle->stat($this->_resourceFile)[
'type'];
214 if ($this->_linkType == self::LINK_TYPE_FILE) {
215 return pathinfo($this->_resourceFile, PATHINFO_BASENAME);
216 }
elseif ($this->_linkType == self::LINK_TYPE_URL) {
217 $stat = $this->_handle->stat($this->_resourceFile);
218 if (isset($stat[
'disposition'])) {
219 $contentDisposition = explode(
'; ', $stat[
'disposition']);
220 if (!empty($contentDisposition[1]) && preg_match(
221 '/filename=([^ ]+)/',
222 $contentDisposition[1],
229 $fileName = @pathinfo($this->_resourceFile, PATHINFO_BASENAME);
245 public function setResource($resourceFile, $linkType = self::LINK_TYPE_FILE)
247 if (self::LINK_TYPE_FILE == $linkType) {
249 if (preg_match(
'#\.\.[\\\/]#', $resourceFile)) {
250 throw new \InvalidArgumentException(
251 'Requested file may not include parent directory traversal ("../", "..\\" notation)' 256 $this->_resourceFile = $resourceFile;
257 $this->_linkType = $linkType;
270 $this->_session->writeClose();
271 while (
true == ($buffer =
$handle->read(1024))) {
285 return $this->scopeConfig->getValue(
286 self::XML_PATH_CONTENT_DISPOSITION,
287 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
elseif(isset( $params[ 'redirect_parent']))
getContentDisposition($store=null)
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Downloadable\Helper\File $downloadableFile, \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDb, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Session\SessionManagerInterface $session, \Magento\Framework\Filesystem\File\ReadFactory $fileReadFactory)
const XML_PATH_CONTENT_DISPOSITION
setResource($resourceFile, $linkType=self::LINK_TYPE_FILE)