Oihana PHP

zipFileInfo.php

Table of Contents

Functions

zipFileInfo()  : array{isValid?: bool, extension?: string, mimeType?: string|null, compression?: string|null, fileCount?: int|null, totalSize?: int|null}
Retrieves detailed information about a zip archive file.

Functions

zipFileInfo()

Retrieves detailed information about a zip archive file.

zipFileInfo(string $filePath[, bool $strictMode = false ]) : array{isValid?: bool, extension?: string, mimeType?: string|null, compression?: string|null, fileCount?: int|null, totalSize?: int|null}

This function inspects the given zip file to determine its validity, MIME type, compression family, number of contained entries, and total uncompressed size.

It uses the ZipArchive class to count entries and sum their uncompressed sizes when the archive is valid.

Parameters
$filePath : string

Absolute path to the zip archive file to inspect.

$strictMode : bool = false

When true, enables strict validation of the zip structure via assertZip(). Default is false for a more lenient check.

Tags
throws
FileException

If the provided file does not exist or is not accessible.

see
assertZip()
author

Marc Alcaraz (ekameleon)

since
1.2.0
example
$info = zipFileInfo( '/archives/sample.zip' );
print_r( $info );

$info = zipFileInfo( '/bad/path.zip' );
var_dump( $info['isValid'] ); // false

// Strict mode
$info = zipFileInfo( '/archives/sample.zip' , true );
Return values
array{isValid?: bool, extension?: string, mimeType?: string|null, compression?: string|null, fileCount?: int|null, totalSize?: int|null}

Returns an associative array keyed by ZipInfo with:

  • isValid: Whether the file is a valid zip according to assertZip().
  • extension: File extension (lowercase) extracted from the path.
  • mimeType: MIME type detected via finfo.
  • compression: CompressionType::ZIP when the MIME type is zip-like, otherwise CompressionType::NONE.
  • fileCount: Number of entries inside the archive (if valid), otherwise null.
  • totalSize: Sum of the uncompressed sizes (in bytes) of all entries (if valid), otherwise null.
On this page

Search results