Oihana PHP

hasZipMimeType.php

Table of Contents

Functions

hasZipMimeType()  : bool
Checks if a file has a zip-related MIME type.

Functions

hasZipMimeType()

Checks if a file has a zip-related MIME type.

hasZipMimeType(string $filePath[, array<string|int, string> $mimeTypes = ['application/zip', 'application/x-zip', 'application/x-zip-compressed', 'application/zip-compressed', 'multipart/x-zip'] ]) : bool

This function inspects the MIME type of the given file against a list of valid zip-related MIME types to determine if the file is a zip archive.

It is a thin wrapper around hasMimeType() pre-configured with the common zip MIME types.

Parameters
$filePath : string

Path to the file.

$mimeTypes : array<string|int, string> = ['application/zip', 'application/x-zip', 'application/x-zip-compressed', 'application/zip-compressed', 'multipart/x-zip']

Optional list of valid zip MIME types. Defaults to common zip types:

  • 'application/zip'
  • 'application/x-zip'
  • 'application/x-zip-compressed'
  • 'application/zip-compressed'
  • 'multipart/x-zip'
Tags
author

Marc Alcaraz (ekameleon)

since
1.2.0
example

Check if a .zip file is a zip archive:

$result = hasZipMimeType('/path/to/archive.zip');
var_dump($result); // bool(true) or bool(false)

Check a non-existent file (returns false):

$result = hasZipMimeType('/path/to/missing.zip');
var_dump($result); // bool(false)
Return values
bool

True if the file exists and its MIME type matches one of the given zip MIME types.

On this page

Search results