Magento2 has a built-in script for any kind of file download, we can use the below code for file downloads:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<?php /** * Magemonkeys. * * @category Magemonkeys * * @author Magemonkeys * @copyright Copyright (c) 2020 Magemonkeys (https://magemonkeys.com/) */ namespace Magemonkeys\Download\Controller\Download; use Magento\Framework\App\Action\Context; /** * file download controller. */ class Index extends \Magento\Framework\App\Action\Action { /** * @var Magento\Framework\App\Response\Http\FileFactory */ protected $_downloader; /** * @var Magento\Framework\Filesystem\DirectoryList */ protected $directory; /** * @param Context $context * @param PageFactory $resultPageFactory */ public function __construct( Context $context, \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Framework\Filesystem\DirectoryList $directory ) { $this->_downloader = $fileFactory; $this->directory = $directory; parent::__construct($context); } public function execute() { $fileName = $this->getRequest()->getParam('fileName'); $file = $this->directory->getPath("media")."/FilePath/".$fileName; // do your validations /** * do file download */ return $this->_downloader->create( $fileName, @file_get_contents($file) ); } } |
[crayon-63d3e3c1f2291050604013/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.