A fresh mix of code snippets and tutorials

PHP fix exif_imagetype() error

Working on my plugin USP Pro, it’s become apparent to me that some servers for whatever reason disable the function exif_imagetype() function. So some users would get an error when trying to upload images. To resolve this, I added the following simple function to the plugin core.

The error

Here is an example of the PHP error that will be triggered if exif_imagetype() is not available on the server:

... Call to undefined function exif_imagetype() ...

The fix

To fix the error, I added the following function to the plugin script:

if (!function_exists('exif_imagetype')) {
	function exif_imagetype($filename) {
		if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) { 
			return $type;
		return false; 

This is entirely plug-n-play solution. It simply provides the same functionality of exif_imagetype() if/when it’s not available. So if you’re using USP Pro, this fix already is included and has you covered. Otherwise, if USP Pro is not installed, you can add the function to your PHP script, WordPress theme or plugin or whatever as needed to provide fallback support for exif_imagetype(). Plug & play, baby.

★ Pro Tip: