Oihana PHP

hasTarExtension.php

Table of Contents

Functions

hasTarExtension()  : bool
Checks if a file has a tar-related extension.

Functions

hasTarExtension()

Checks if a file has a tar-related extension.

hasTarExtension(string $filePath[, array<string|int, string> $tarExtensions = [ FileExtension::TAR, FileExtension::TGZ, FileExtension::GZ, FileExtension::TAR_GZ, FileExtension::TAR_BZ2, FileExtension::BZ2, // Written by the system tar since 1.5.0, so they have to be recognised as tar // archives or the library could no longer read back what it writes. Taken from // TarExtension, which is the catalogue of tar extensions — `.gz` and `.bz2` above // are not, which is exactly why they surprise. TarExtension::TAR_XZ, TarExtension::TXZ, TarExtension::TAR_ZST, ] ]) : bool
Parameters
$filePath : string

Path to the file.

$tarExtensions : array<string|int, string> = [ FileExtension::TAR, FileExtension::TGZ, FileExtension::GZ, FileExtension::TAR_GZ, FileExtension::TAR_BZ2, FileExtension::BZ2, // Written by the system tar since 1.5.0, so they have to be recognised as tar // archives or the library could no longer read back what it writes. Taken from // TarExtension, which is the catalogue of tar extensions — `.gz` and `.bz2` above // are not, which is exactly why they surprise. TarExtension::TAR_XZ, TarExtension::TXZ, TarExtension::TAR_ZST, ]

Optional list of valid tar-related extensions. Defaults to common tar and compressed tar extensions:

  • .tar
  • .tgz
  • .gz
  • .tar.gz
  • .tar.bz2
  • .bz2
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0
example

Check a simple tar file:

var_dump(hasTarExtension('/path/to/archive.tar')); // bool(true)

Check a gzipped tar file:

var_dump(hasTarExtension('/path/to/archive.tar.gz')); // bool(true)

Check a file with .tgz extension:

var_dump(hasTarExtension('/path/to/archive.tgz')); // bool(true)

Check a file with unsupported extension:

var_dump(hasTarExtension('/path/to/archive.zip')); // bool(false)

Check a file with double extension .tar.bz2:

var_dump(hasTarExtension('/path/to/archive.tar.bz2')); // bool(true)
Return values
bool —

True if the file has a recognized tar extension.

On this page

Search results