Title: wp_zip_file_is_valid
Published: April 3, 2024
Last modified: April 28, 2025

---

# wp_zip_file_is_valid( string $file ): bool

## In this article

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

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

Determines whether the given file is a valid ZIP file.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_zip_file_is_valid/?output_format=md#description)󠁿

This function does not test to ensure that a file exists. Non-existent files are
not valid ZIPs, so those will also return false.

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

 `$file`stringrequired

Full path to the ZIP file.

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

 bool Whether the file is a valid ZIP file.

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

    ```php
    			$archive->close();
    			return true;
    		}
    	}

    	// Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
    	require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';

    	$archive          = new PclZip( $file );
    	$archive_is_valid = is_array( $archive->properties() );

    	return $archive_is_valid;
    }

    /**
     * Unzips a specified ZIP file to a location on the filesystem via the WordPress
     * Filesystem Abstraction.
     *
     * Assumes that WP_Filesystem() has already been called and set up. Does not extract
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/file.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/file.php#L1571)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/file.php#L1571-L1589)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_zip_file_is_valid/?output_format=md#hooks)󠁿

 [apply_filters( ‘unzip_file_use_ziparchive’, bool $ziparchive )](https://developer.wordpress.org/reference/hooks/unzip_file_use_ziparchive/)

Filters whether to use ZipArchive to unzip archives.

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

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [File_Upload_Upgrader::__construct()](https://developer.wordpress.org/reference/classes/file_upload_upgrader/__construct/)`wp-admin/includes/class-file-upload-upgrader.php` |

Construct the upgrader for a form.

  |

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

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

## User Contributed Notes

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