Archive_Tar::extract()

Archive_Tar::extract() – extract files

Synopsis

require_once 'Archive/Tar.php';

boolean extract ( string $path )

Description

Extracts the files from the archive into the given path.

While extracting a file: If the file already exists it is replaced without looking for last modification date. If the file already exists and is write protected, the extraction is aborted. If a directory with the same name already exists, the extraction is aborted.

However the result can be a partial extraction that may need to be manually cleaned.

Parameter

  • string $path - the destination path to extract

Return value

boolean - Returns TRUE on success, FALSE on failure.

Throws

Possible PEAR_Error values
Error code Error message Reason Solution
NULL " Unable to open in read mode archive " The file is exclusively locked by another application. Check for other applications working on the file. This can not be caused by a competive processing the archive with Archive_Tar
NULL " Unable to open in write mode archive " The file is locked by another application. Check for other applications working on the file. This maybe caused by a competive processing the archive with Archive_Tar
NULL " Invalid extract mode mode " Implementation error Should not occur, please set up a bug report.
NULL " Directory name already exists as a file " A file is marked up as directory in the archive. Maybe a corrupted archive.
NULL " File name already exists as a directory " A directoy is marked up as file in the archive. Maybe a corrupted archive.
NULL " File name already exists and is write protected. " The archive contains a file which already exists in the destination dir and can not be overwritten. Extract the archive to an empty directory.
NULL " Unable to create path for name " One or more new nested directories could not be created in the destination directory. Ensure that the destination directory and all nested directories have the required permissions.
NULL " Unable to create directory name " A directory could not be created in the destination directory. Ensure that the destination directory has the required permissions.
NULL " Error while opening name in write binary mode " The file could not be created. The file is possibly locked.
NULL " Extracted file filename does not have the correct file size filesize (size expected). Archive may be corrupted. " Read the message. Read the message.

Note

This function can not be called statically.

Example

Extract compressed archive

<?php
$tar 
= new Archive_Tar('archive.tar.gz'true);
$result $tar->extract('/home/myFolder');
?>