In this post I am going to explain how to check file exists in directory using isExists method in magento 2.
Use below code snippet to check file is exists or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | private $_fileDriver; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Framework\Filesystem\Driver\File $fileDriver, array $data = [] ) { $this->_fileDriver = $fileDriver; parent::__construct($context, $data); } public function getFileExists() { $file = '/home/user/public_html/pub/media/logo/default/logo.png'; if ($this->_fileDriver->isExists($file)) { return "Yes"; } else { return "No"; } } |
Thats it. Enjoy Magento 2!!
Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!
Leave a Reply