PharData tar and zip file
PHP File Function: PharData tar and zi file process
Categories:
Create zip or tar file
$zip_file_path = '/var/zip/file/path.zip';
$ArchiveZipFile = new \PharData($zip_file_path);
$tar_file_path = '/var/tar/file/path.tar.gz';
$ArchivetarFile = new \PharData($tar_file_path);
Function
PharData::extractTo
public PharData::extractTo(
string $directory
,array|string|null $files = null
,bool $overwrite = false
):bool
Extract the contents of a tar/zip archive to a directory
$zip_file_path = '/var/zip/file/path.zip';
$ArchiveZipFile = new \PharData($zip_file_path);
// extract all files
$ArchiveZipFile->extractTo('/full/path');
// extract only file.txt
$ArchiveZipFile->extractTo('/another/path', 'file.txt');
// extract 2 files only
$ArchiveZipFile->extractTo('/this/path', array('file1.txt', 'file2.txt'));
// extract all files, and overwrite
$ArchiveZipFile->extractTo('/third/path', null, true);
getFilename()
public DirectoryIterator::getFilename():
string
Return file name of current DirectoryIterator item
$zip_file_path = '/var/zip/file/path.zip';
$ArchiveZipFile = new \PharData($zip_file_path);
$ArchiveZipFile->getFilename();