untar.php
Table of Contents
Functions
- untar() : true|array<string|int, string>
- Extracts a tar archive file into a specified output directory.
Functions
untar()
Extracts a tar archive file into a specified output directory.
untar(string $tarFile, string $outputPath[, array{dryRun?: bool, keepPermissions?: bool, overwrite?: bool} $options = [] ]) : true|array<string|int, string>
This function supports regular and compressed tar files (.tar, .tar.gz, .tar.bz2). It can perform a dry run to preview extracted files, optionally preserve file permissions, and control overwriting of existing files.
Parameters
- $tarFile : string
-
Path to the tar archive file to extract.
- $outputPath : string
-
Path to the directory where files will be extracted. The directory will be created if it does not exist.
- $options : array{dryRun?: bool, keepPermissions?: bool, overwrite?: bool} = []
-
Optional flags:
- dryRun: If true, the function does not extract files but returns the list of files that would be extracted. Default: false.
- keepPermissions: If true, preserves the original file permissions from the archive. Default: false.
- overwrite: If false, prevents overwriting existing files during extraction. Extraction will fail if a file already exists. Default: true.
Tags
Return values
true|array<string|int, string> —Returns true on successful extraction, or an array of file paths (relative to archive root) if dryRun is enabled.