7

Any time I try to add images to a product in Magento 2.1 I get the following error:

Attention: We don't recognize or support this file extension type.

It does not matter what type of image I attempt to upload. I went through the whole list of supported file types. I tried it with a simple product and with a configurable product.

Does anyone know how to fix this issue? This question was asked before here but the answers misunderstood the question and are not helpful.

2
  • Flash is possibly the issue. Browsers are blocking it. Finding I have to use Firefox.
    – user66194
    Commented Mar 29, 2018 at 5:47
  • @user66194 - You might be confusing this question with another issue. Magento 2.1+ and 2.2+ does not use flash to upload or display images. You technically could install a third party extension that uses flash for some reason but this is highly unlikely and sounds like a terrible idea; in my case (OP) flash is definitely not the issue, see my answer below. Commented Mar 29, 2018 at 6:33

10 Answers 10

20

Solved
This error can be caused by several server configuration issues. Each error will always present itself with the same generic warning from Magento 2: Attention: We don't recognize or support this file extension type. If your using Magento 2.2.0+ the error may be worded differently. Below are the most common server settings that are causing this error. There may be more than this list but these are all I have personally tested.

1) Permission Problem
You may get an error along the lines of "Can not create directory pub/media/tmp" or you may notice after examining the XHR summary in developer tools that a 200 success code is returned but no data was saved to the server. The easiest way to test this to check your server's permissions and make sure all the directories, especially everything under pub/media are 755. You may have a mix of the following issues as well so do not stop troubleshooting permissions until you check them as well.

2) Missing Write Permissions to Upload Directory / Missing Directory
PHP needs to use the server's temporary upload directory when uploading files to the server. Make sure that your server has a temporary upload directory setup and is writable by the Magento user; whichever user you are using for your Magento website. Most hosting providers have this setup for you but some may lock down this feature or maybe missing a default setting. Private servers sometimes rely on you choosing the temporary upload directory per domain and then defaulting to a generic location if you failed to choose one. Look in your php.ini (phpinfo) for upload_tmp_dir. No value means the server will use the default if it can find any.

3) Insufficient max file size and post file size
In your php.ini file you need to correctly set your upload_max_filesize and post_max_size. If any image or any upload of images exceeds these settings you will get the error from the OP. Remember this rule:

post_max_size must be >= upload_max_filesize

Also, note that your web host will most likely not warn you if you entered an incorrect value here. You could mistype the value or choose a size the web host does not allow. Test for this.

4) PHP GD (image processing) extension missing
You should have been warned during install if you were missing this extension but PHP upgrades on your server could have disabled it. The fastest way to check this setting is to look through the printout of phpinfo() but you can look it up in cPanel or your Apache/PHP provisioning on an Apache server.

5) PHP ImageMagick (image processing) extension missing
Starting with Magento 2.2.0+ Magento would like to use ImageMagick as well. The documentation is not too clear but it appears you can use one or both of these PHP extensions. If you upgrade to or install PHP 7+ on your server there is a chance it will disable GB and enable ImageMagick depending on how your provisioning your server. Just check that one if not both them is enabled and working correctly.

Test Script
The following is a PHP script you can use to test for some of these issues. Make a simple HTML form with one file input field named upfile and set the form action to submit to wherever you place this script on your server. You will need to create an uploads directory in the same directory as this script. It is not my code, it was originally posted to the PHP Manual by CertaiN.

<?php

header('Content-Type: text/plain; charset=utf-8');

try {

// Undefined | Multiple Files | $_FILES Corruption Attack
// If this request falls under any of them, treat it invalid.
if (
    !isset($_FILES['upfile']['error']) ||
    is_array($_FILES['upfile']['error'])
) {
    throw new RuntimeException('Invalid parameters.');
}

// Check $_FILES['upfile']['error'] value.
switch ($_FILES['upfile']['error']) {
    case UPLOAD_ERR_OK:
        break;
    case UPLOAD_ERR_NO_FILE:
        throw new RuntimeException('No file sent.');
    case UPLOAD_ERR_INI_SIZE:
    case UPLOAD_ERR_FORM_SIZE:
        throw new RuntimeException('Exceeded filesize limit.');
    default:
        throw new RuntimeException('Unknown errors.');
}

// You should also check filesize here. 
if ($_FILES['upfile']['size'] > 1000000) {
    throw new RuntimeException('Exceeded filesize limit.');
}

// DO NOT TRUST $_FILES['upfile']['mime'] VALUE !!
// Check MIME Type by yourself.
$finfo = new finfo(FILEINFO_MIME_TYPE);
if (false === $ext = array_search(
    $finfo->file($_FILES['upfile']['tmp_name']),
    array(
        'jpg' => 'image/jpeg',
        'png' => 'image/png',
        'gif' => 'image/gif',
    ),
    true
)) {
    throw new RuntimeException('Invalid file format.');
}

// You should name it uniquely.
// DO NOT USE $_FILES['upfile']['name'] WITHOUT ANY VALIDATION !!
// On this example, obtain safe unique name from its binary data.
if (!move_uploaded_file(
    $_FILES['upfile']['tmp_name'],
    sprintf('./uploads/%s.%s',
        sha1_file($_FILES['upfile']['tmp_name']),
        $ext
    )
)) {
    throw new RuntimeException('Failed to move uploaded file.');
}

echo 'File is uploaded successfully.';

} catch (RuntimeException $e) {

echo $e->getMessage();

}

?>
1
  • 1
    Considering Imagemagick one must check if "ImageMagick supported formats" list is filled with image extensions on phpinfo() page. My supported formats gone after updating ImageMagick.
    – Gediminas
    Commented Oct 26, 2018 at 12:39
4

In my case, I need to enable fileinfo extension for PHP to make it work. If I disable fileinfo extension, it will generate this error again. I m using php 7.2, Magento 2.3.3 community version.

1
  • Thanks this worked for me. I was getting the following error for a JPG which was strange. "test.jpg was not uploaded. Disallowed File Type.". Commented Oct 27, 2019 at 19:18
3

I fixed it in cPanel > PHP Selector extensions when I had the same error:

  1. Select gd
  2. Select xsl

Then I tried to upload images again and this error is not there anymore.

enter image description here

0
3

In our experience this can also be caused by the server/hosting being out of space (i.e. disk full).

1

Check phpinfo() page, if file_uploads is off, set file_uploads on enter image description here

1

I did this for me :

sudo chmod -R 777 pub/media/tmp

It is working now

1
  • This falls under point 1 in my answer. You should use 755 instead of 777. Commented Oct 10, 2018 at 6:31
0

Probably is a permission problem. Check the ajax response when you try to upload the image. If returns an error with message "Can not create directory pub/media/tmp...", then you just have to set correct permissions for "pub/media" directory.

1
  • No errors are reported what-so-ever. Console or back-end logs. I tested your theory about permission issues and everything is working as expected. No permission issues, no errors, status 200 always returns. It doesn't seem to be a permissions problem. You can see track the progress of this bug here: github.com/magento/magento2/issues/5845 Commented Aug 2, 2016 at 17:38
0

I ran into same issue,suddenly magento 2 start getting message "We don't recognize or support this file extension type." I solved it by

  1. clean cache(php bin/magento cache:clean)
  2. flush cache(php bin/magento cache:flush)
  3. reindex (php bin/magento indexer:reindex)
  4. logout from the backend and login again
0

Had the same error on local environment.

The error was due to an nginx permissions error.

Running this on macOS with local brew services nginx.

Local dev env

  • macOS
  • brew services nginx, php7.2
  • Magento 2.3.4

Error in the /usr/local/var/log/nginx/error.log file was

 [crit] 7566#0: *31067 open() "/usr/local/var/run/nginx/client_body_temp/0000000035" failed (13: Permission denied), client: 127.0.0.1, 

Solution for this error

Change the owner for the folders under /usr/local/var/run/nginx/

For instance, I fixed it with

sudo chown myloginuser:admin -R /usr/local/var/run/nginx

Now I can upload product images. So maybe try this if you encounter this issue.

0

In my case, it was SELinux that was causing the issue with it being on 'enforced' mode.

To check if your SELinux status on your server, type

sestatus

Permissive vs. Enforcing Mode:

  • Enforcing: SELinux policies are actively enforced, and access is
    restricted according to the policies.

  • Permissive: SELinux policies are not enforced but violations are logged, which can be useful for troubleshooting without impacting operations.

  • Disabled: SELinux is turned off.

Check if the status is 'enforced' or 'permissive'. If 'enforced', change to permissive temporarily by typing

setenforce 0

This change should be in effect until the next server reboot, or edit the SELinux config file to make the change permanent.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.