User Tools

Site Tools


uphp:functions:tar_finish

tar_finish

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

Add the ending header to a TAR file

Description

int tar_finish ( int $handle )

This function will attempt to add the ending header to a previously opened file in TAR format1). To use this function, first open the file using fopen(), then call tar_put() as many times as needed to add individual files. When finished adding files call this function to add the ending header and close the file (releasing the handle).

Parameters

$handle: Valid handle of the already opened file. This is obtained from the previous call to fopen() specifying 'w' for write mode.

Return Values

Integer: 1 if successful, or 0 if the attempt to finish the TAR failed

Example

Create a TAR archive containing all of the files in /config/

<?
  $handle=fopen("/tar_put_example.tar",'w'); // open TAR for writing
  $path="/config/";
  chdir($path);
  $aFile=findfirst("*.*",255-16); // get the first file, excluding directories
  while ($aFile) {
    tar_put($handle,$path.$aFile['filename'],$aFile['filename']);     
    $aFile=findnext(); // get the next file
  }                    // loop until no more files
  tar_finish($handle); // finish and close the TAR
?>

See Also

fopen() - Open a file for reading or writing

tar_put() - Add a file to an open file in TAR format

chdir() - Change the current directory

findfirst() - Start searching the current folder for files matching a pattern and attributes

findnext() - Return next matching file information (after a findfirst)

untar() - Expand a TAR file into the current folder, optionally verbose

1)
The TAR format is used to collect many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name for the TAR utility was derived from Tape ARchive, as it was originally developed to write data to sequential I/O devices with no file system of their own. In addition to the contents of the files the TAR archive can contain information on the file system parameters, such as name, time stamps, ownership, file access permissions and directory organization.
uphp/functions/tar_finish.txt · Last modified: 2021/09/13 05:57 (external edit)