User Tools

Site Tools


uphp:functions:tar_put

tar_put

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

Add a file to an open file in TAR format

Description

int tar_put ( int $handle, string $src_pathname, string $tar_pathname )

This function will attempt to add a single file 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 close the TAR file with tar_finish().

Parameters

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

$src_pathname: Full path and filename of the source file to add to the TAR. Relative paths are not supported, so this parameter must begin with / to specify that the path begins in the root folder.

$tar_pathname: Path and filename for the TAR archive of this file, usually without a leading /. The path within the TAR can be specified differently than the source path in order to create a directory organization in the TAR that is not the same as the organization of the source files. Or the path can be omitted completely if you desire to place the file(s) in the root of the TAR (in this case be sure not to precede the filename with /, see Example). The filename can also be specified differently than the source, but this is not usually desirable.

Return Values

Integer: 1 if successful, or 0 if the attempt to add the file 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_finish() - Add the ending header to a TAR file

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_put.txt · Last modified: 2021/09/13 05:57 (external edit)