🔥 Just Launched! Werra Premium Template for HyväSee it in Action

Solved: Use of $_FILES is Discouraged in Magento 2

By Sanjay JethvaUpdated on May 22, 2025 2 min read

The direct use of global variables such as $_FILES, $_GET, $_POST, can lead to security vulnerabilities and it is against the Magento coding standards. Thus, the direct usage of such global variables in Magento may throw an exception and show warnings.

In case you have tried using the $_FILES variable directly in your code, you may encounter the following warning: ‘Use of $_FILES is discouraged in Magento 2’.

 45 | WARNING | The use of function filectime() is discouraged
 46 | WARNING | The use of function filemtime() is discouraged

That means you can not directly use the global variable $_FILES in your code and may require to seek for an alternate method to using it.

You may require to use these global variables at various points, in case you are developing any custom functionality in your Magento store such as Magento extension. Therefore, in this post, I have provided a complete solution on how you can use the $_FILES global variable in your code indirectly to prevent the error.

A solution to the Error – Use of $_FILES is discouraged in Magento 2:

Instead of directly using the global variable $_FILES in Magento, you can use the getFiles() to retrieve the files and prevent the error in Magento 2. You can use the following code to do that:

use Magento\Framework\App\Request\Http;
$files = $this->httprequest->getFiles();

That’s it.

Also, do share the post with the Magento Community via social media.

Thank you.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.