Title: _wp_check_existing_file_names
Published: April 1, 2020
Last modified: May 20, 2026

---

# _wp_check_existing_file_names( string $filename, array $files ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Helper function to check if a file name could match an existing image sub-size file
name.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#parameters)󠁿

 `$filename`stringrequired

The file name to check.

`$files`arrayrequired

An array of existing files in the directory.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#return)󠁿

 bool True if the tested file name could match an existing file, false otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#source)󠁿

    ```php
    function _wp_check_existing_file_names( $filename, $files ) {
    	$fname = pathinfo( $filename, PATHINFO_FILENAME );
    	$ext   = pathinfo( $filename, PATHINFO_EXTENSION );

    	// Edge case, file names like `.ext`.
    	if ( empty( $fname ) ) {
    		return false;
    	}

    	if ( $ext ) {
    		$ext = ".$ext";
    	}

    	$regex = '/^' . preg_quote( $fname ) . '-(?:\d+x\d+|scaled|rotated)' . preg_quote( $ext ) . '$/i';

    	foreach ( $files as $file ) {
    		if ( preg_match( $regex, $file ) ) {
    			return true;
    		}
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/functions.php#L2847)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/functions.php#L2847-L2869)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#related)󠁿

| Used by | Description | 
| [_wp_check_alternate_file_names()](https://developer.wordpress.org/reference/functions/_wp_check_alternate_file_names/)`wp-includes/functions.php` |

Helper function to test if each of an array of file names could conflict with existing files.

  | 
| [wp_unique_filename()](https://developer.wordpress.org/reference/functions/wp_unique_filename/)`wp-includes/functions.php` |

Gets a filename that is sanitized and unique for the given directory.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_wp_check_existing_file_names/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.3.1](https://developer.wordpress.org/reference/since/5.3.1/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_wp_check_existing_file_names%2F)
before being able to contribute a note or feedback.