file_is_valid_image() WordPress Function

The file_is_valid_image() function is a utility function that allows you to check if a given file is a valid image file. This is useful when you want to allow users to upload images to your website, for example. The function returns true if the file is a valid image, and false otherwise.

file_is_valid_image( string $path ) #

Validate that file is an image.


Parameters

$path

(string)(Required)File path to test if valid image.


Top ↑

Return

(bool) True if valid image, false if not valid image.


Top ↑

Source

File: wp-admin/includes/image.php

function file_is_valid_image( $path ) {
	$size = wp_getimagesize( $path );
	return ! empty( $size );
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.