# unzip_file()

URL: https://chugunov.pro/api-wordpress/functions/unzip_file/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.5.0.

## Сигнатура

```php
unzip_file( string $file, string $to ): true|WP_Error
```

## Описание

Предполагается, что WP_Filesystem() уже вызвана и настроена. Не извлекает каталог __MACOSX верхнего уровня, если он присутствует.
Перед распаковкой пытается увеличить лимит памяти PHP до 256M. Тем не менее максимально требуемый объём памяти не должен намного превышать размер самого архива.

## Параметры

- `$file` `string` — обязательный. Полный путь и имя файла ZIP-архива.
- `$to` `string` — обязательный. Полный путь в файловой системе, куда извлечь архив.

## Возвращаемое значение

`true|WP_Error` — WP_Error

## Исходный код

Файл: `wp-admin/includes/file.php:1603`

```php
function unzip_file( $file, $to ) {
	global $wp_filesystem;

	if ( ! $wp_filesystem || ! is_object( $wp_filesystem ) ) {
		return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
	}

	// Unzip can use a lot of memory, but not this much hopefully.
	wp_raise_memory_limit( 'admin' );

	$needed_dirs = array();
	$to          = trailingslashit( $to );

	// Determine any parent directories needed (of the upgrade directory).
	if ( ! $wp_filesystem->is_dir( $to ) ) { // Only do parents if no children exist.
		$path = preg_split( '![/\\\]!', untrailingslashit( $to ) );
		for ( $i = count( $path ); $i >= 0; $i-- ) {
			if ( empty( $path[ $i ] ) ) {
				continue;
			}

			$dir = implode( '/', array_slice( $path, 0, $i + 1 ) );
			if ( preg_match( '!^[a-z]:$!i', $dir ) ) { // Skip it if it looks like a Windows Drive letter.
				continue;
			}

			if ( ! $wp_filesystem->is_dir( $dir ) ) {
				$needed_dirs[] = $dir;
			} else {
				break; // A folder exists, therefore we don't need to check the levels below this.
			}
		}
	}

	/**
	 * Filters whether to use ZipArchive to unzip archives.
	 *
	 * @since 3.0.0
	 *
	 * @param bool $ziparchive Whether to use ZipArchive. Default true.
	 */
	if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
		$result = _unzip_file_ziparchive( $file, $to, $needed_dirs );
		if ( true === $result ) {
			return $result;
		} elseif ( is_wp_error( $result ) ) {
			if ( 'incompatible_archive' !== $result->get_error_code() ) {
				return $result;
			}
		}
	}
	// Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
	return _unzip_file_pclzip( $file, $to, $needed_dirs );
}
```

## История изменений

- 2.5.0 — Introduced.

## Связанные

Использует: [`wp_raise_memory_limit`](https://chugunov.pro/api-wordpress/functions/wp_raise_memory_limit/), [`_unzip_file_ziparchive`](https://chugunov.pro/api-wordpress/functions/_unzip_file_ziparchive/), [`_unzip_file_pclzip`](https://chugunov.pro/api-wordpress/functions/_unzip_file_pclzip/), [`untrailingslashit`](https://chugunov.pro/api-wordpress/functions/untrailingslashit/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`trailingslashit`](https://chugunov.pro/api-wordpress/functions/trailingslashit/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/), `WP_Error::__construct`.
Используется в: `WP_Upgrader::unpack_package`.

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/unzip_file/
