In this tutorial, We’ll learn how to remove file_exists in Magento 2. Magento does not support direct use of file_exists in file. This practice is not supportable by coding standard and this can be cause of security issues. So when you check phpcs issues then you will see “file_exists is discouraged”.

You must use an alternative method of file_exists when using Magento 2 to avoid this problem.
<?php
/**
* @var \Magento\DownloadableImportExport\Helper\Uploader
*/
protected $uploaderHelper;
/**
* @param \Magento\DownloadableImportExport\Helper\Uploader $uploaderHelper
*/
public function __construct(
\Magento\DownloadableImportExport\Helper\Uploader $uploaderHelper
) {
$this->uploaderHelper = $uploaderHelper;
}
public function isFile($fileName)
{
if ($this->uploaderHelper->isFileExist($fileName)) {
//write your code
}
}
I hope this article is simple to grasp.
If you still have any issue feel free to ask and let me know your views to make the better. Share this solution with your other Magento buddies via social media.
Thanks for reading.