CSV File Download Programmatically in Magento 2
Please check the below code,
<?php
namespace Webkul\Csv\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Filesystem\DirectoryList;
class GetFile extends Action
{
public function __construct(
Context $context,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory
) {
$this->fileFactory = $fileFactory;
parent::__construct($context);
}
public function execute()
{
$filepath = 'export/customerlist.csv';
$downloadedFileName = 'CustomerList.csv';
$content['type'] = 'filename';
$content['value'] = $filepath;
$content['rm'] = 1;
return $this->fileFactory->create($downloadedFileName, $content, DirectoryList::VAR_DIR);
}
}
0 comments:
Post a Comment
Thanks