XF 1.5 The contents of the uploaded image do not match the file's extension



The error "The contents of the uploaded image do not match the file's extension" happens when you upload .jpg file while the image format is .png or whatever. I know I can convert image by my hands to desired format and upload the fixed one... But for common forum visitors it's a very annoying and frustrating error.

Is there a way to fix it and forget about the term 'wrong image type' entirely? For example, I have ImageMagic installed, well is there a way to order xenforo "if image is of wrong type -> convert it so it fits requirements"?

Thanks for your support.

Chris D

XenForo developer
Staff member
The file doesn't need to be converted it just needs the extension to be changed. There isn't a way to change the system to ignore that error.

Mr Lucky

Well-known member
I've never heard of the, why would a png file have the .jpg extension in the first place?


Thank you for your response @Chris D !

this check is performed in library/Xenforo/Upload.php
        $type = $imageInfo['type'];
        $extensionMap = array(
            IMAGETYPE_GIF => array('gif'),
            IMAGETYPE_JPEG => array('jpg', 'jpeg', 'jpe'),
            IMAGETYPE_PNG => array('png')
        if (!isset($extensionMap[$type]))
            return; // only consider gif, jpeg, png to be images in this system
        if (!in_array($this->_extension, $extensionMap[$type]))
             $this->_errors['extension'] = new XenForo_Phrase('contents_of_uploaded_image_do_not_match_files_extension');
well, in order to tell Xenforo rename files on-the-fly without disturbing user I think we can do something like this:

        if (!in_array($this->_extension, $extensionMap[$type]))
            $filename_noext = str_replace($this->_extension,'',$this->_fileName);
            $this->_extension = $extensionMap[$type][0]; // set the extention desired
            $this->_fileName = $filename_noext . $this->_extension;
            // $this->_errors['extension'] = new XenForo_Phrase('contents_of_uploaded_image_do_not_match_files_extension');
is that correct? do I need to call
setFileName ($fileName);
or something similar once again to tell Xenforo rename the file name to be created on disk? Sorry for possible syntax mistakes, I'm not a programmer.

Thanks in advance!

P. S. @Mr Lucky, users often save files on computer with the filename which already exists (when making screenshots etc.). In windows, for example, they click "save", then doubleclick the existent file to rewrite it, "rewrite this file?" -> "yes". Previous file could be saved as .jpg, the next one has .png format but ends up been saved with .jpg extension. It happens a lot.
Last edited: