file_is_displayable_image

函数
file_is_displayable_image ( $path )
参数
  • (string) $path File path to test.
    Required:
返回值
  • (bool) True if suitable, false if not suitable.
定义位置
相关方法
file_is_valid_imagedisplay_space_usagemaybe_disable_link_manageris_gd_imagemedia_upload_image
引入
2.5.0
弃用
-

file_is_displayable_image – 这个函数检查一个文件是否是一个可以在网络浏览器中显示的有效图像。它接受文件路径作为其唯一的参数。

验证该文件是否适合在网页中显示。

function file_is_displayable_image( $path ) {
	$displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP );

	$info = wp_getimagesize( $path );
	if ( empty( $info ) ) {
		$result = false;
	} elseif ( ! in_array( $info[2], $displayable_image_types, true ) ) {
		$result = false;
	} else {
		$result = true;
	}

	/**
	 * Filters whether the current image is displayable in the browser.
	 *
	 * @since 2.5.0
	 *
	 * @param bool   $result Whether the image can be displayed. Default true.
	 * @param string $path   Path to the image.
	 */
	return apply_filters( 'file_is_displayable_image', $result, $path );
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 14:32:54

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: