×


'Error InvalidArgumentException wrong file' in Magento 2 - fix it Now ?

Magento is an open-source e-commerce platform written in PHP. While installing Magento sometimes we may end up with this error. Error InvalidArgumentException wrong file happens when there is an issue with the PHP configuration settings.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to resolve related Magento errors.


Main causes 'error InvalidArgumentException wrong file' in Magento 2

Before going into the steps for fixing this error we will see what causes it.

A typical error looks like the one given below:

[ERROR] InvalidArgumentException: Wrong file in C:\Users\admin\Desktop\demo\htdocs\magento2\vendor\magento\framework\Image\Adapter\Gd2.php:64 Stack trace: #0

Below are some of the causes for this error:

  • PHP memory limit.
  • Missing PHP extension.
  • Another possible reason for this error could be that the PHP version and the composer version are not up to date.


How to fix 'error InvalidArgumentException wrong file' in Magento 2 ?

Following are the methods with which we can fix this error:

1. Increasing PHP memory limit

We must make the following changes in your php.ini file.

It is always better to take a backup of the configuration files before editing them.

In the php.ini file, we must increase the values of the following parameters:

max_execution_time = 18000
max_input_time = 1800
memory_limit = 1024M

2. Checking for missing PHP extensions

We must ensure that the following extensions are enabled in the php.ini file:

bc-math 
ctype
curl
dom
gd, ImageMagick 6.3.7 (or later) or both
intl
mbstring
mcrypt
hash
openssl
PDO/MySQL
SimpleXML
soap
spl
libxml
xsl
zip
json
iconv

The GD extension for the image library must be checked specifically. If not found we can enable it by removing ; (Semicolon) from the php.ini file

Furthermore, if any changes are made in the configuration we must restart the xampp server after saving the changes.


3. Latest technical stack

At times the PHP version and the composer version may not be up to date.

Moreover, the technology stack is said to be correct if we are using the latest PHP version  7.3 and Composer version – 1.10.5.


In Windows server, to fix 'error InvalidArgumentException wrong file' in Magento 2:

In the windows server, when the Image Adapter tries to open to image files (‘open function in Gd2.php line 63). validateURLScheme function returns false always. This is because it checks ‘URL’ format but the local files are not valid for this format, so it returns false.

To fix this we can do the following:

Find validateURLScheme function in vendor\magento\framework\Image\Adapter\Gd2.php file. at line 96.

And replace the function with the following:

private function validateURLScheme(string $filename) : bool
  {
      $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
      $url = parse_url($filename);
      if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) {
          return false;
      }
      return true;
  }


[Need to fix Magento errors? We are happy to help you. ]


Conclusion

This article covers methods to resolve 'Error InvalidArgumentException wrong file' in Magento 2 for our customers. 

You can resolve this error by applying the following changes in your php.ini file.

In your php.ini file increase values of below parameters:

max_execution_time = 18000
max_input_time = 1800
memory_limit = 1024M

Note : Make sure you increase max_input_time value to at least 1800 and it will works.