PHP Classes

TAR/GZIP/BZIP2/ZIP Archives: Create tar/gzip/bzip2/zip, extract tar/gzip/bzip2.

Recommend this page to a friend!

  Author Author  
Name: Devin Doucette <contact>
Classes: 3 packages by
Country: Canada Canada
Age: 30
All time rank: 201 in Canada Canada
Week rank: 606 Down14 in Canada Canada Down

  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
Allows the creation of tar, gzip, bzip2, and zip archives, and the extraction of tar, gzip, and bzip2. Supports relative paths/no paths, comments, and recursing through subdirectories. Can write file to disk, allow user to download directly, or return file contents in a string or an array. Does not require any external programs to run. PHP must be compiled with '--with-zlib' for gzip and zip and '--with-bzip2' for bzip2. Supports creation of self-extracting zip archives. See readme for full details.

By Devin Doucette
Copyright (c) 2005 Devin Doucette

PHP 4 or greater (there is a chance tar and zip archives will work with PHP 3)
Compiled using --with-bz2 for bzip2 support.
Compiled using --with-zlib for gzip and zip support.
 (Zip archives created using method 0 do not require zlib)

- Can create tar, gzip, bzip2, and zip archives.
- Can create self-extracting zip archives.
- Can recurse through and store directories.
- Can create archives in memory or on disk.
- Can allow client to download file directly from memory.
- Errors are placed in an array named "errors" in the object.
- Supports in zip file comments.
- Files are automatically sorted within archive for greater 
  compression in gzip and bzip2 archives.
- Supports archiving and extraction of symbolic links (not 
  applicable for zip files).

Bzip2 and gzip archives are always created as tar files and then compressed, so the 
recommended file extensions are .tbz/.tbz2 and .tgz respectively.

- Currently only USTAR archives are supported for tar file extraction.
- Only bzip2 and gzip files that contain a tar file can be extracted. (Opening these 
  files otherwise is already supported by PHP)
- Cannot extract zip files. (This feature is already supported by PHP)

Extraction of bzip2 and gzip archives is limited to compatible tar files that have 
been compressed by either bzip2 or gzip.  For greater support, use the functions 
bzopen and gzopen respectively for bzip2 and gzip extraction.

Zip extraction is not supported due to the wide variety of algorithms that may be 
used for compression and newer features such as encryption.  If you need to extract 
zip files, use the functions detailed at

Downloading Files:
The download_file function only works for files that are stored in memory.  To have 
users download files that are on disk redirect to the file, or use the following method: 
- Send the appropriate Content-Type header for the file being sent.
- Send a "Content-Disposition: attachment; filename=[insert filename]" header.
- Write out the file contents.

For tar use tar_file (eg. $example = new tar_file("example.tar");)
For gzip use gzip_file (eg. $example = new gzip_file("example.tgz");)
For bzip2 use bzip_file (eg. $example = new bzip_file("example.tbz");)
For zip use zip_file (eg. $example = new zip_file("");)

To set options, send an array containing the options that you wish to set to the 
function set_options. (eg. $example->setoptions($options);)
The options array can include any of the following:

basedir (default ".")
   Sets the that all filenames are taken as being relative to (except optional sfx header).
   Used both when creating and when extracting (will extract to basedir if inmemory == 0).

name (no default)
   The name (and path, if necessary) of the archive, relative to basedir.
   Should be set when creating object (eg. $example = new zip_file("test/");).

prepend (no default)
   The path that is added to the beginning of every filename in the archive.
   Example: If prepend is set to "src/zlib/" then the file "docs/readme.txt" will be 
      stored in the archive as "src/zlib/docs/readme.txt".

inmemory (default 0)
   Set to 1 to create/extract archive in memory, set to 0 to write to disk.

overwrite (default 0)
   Set to 1 to overwrite existing files when creating/extracting archives.
   If set to 0, will give error message if file already exists.

recurse (default 1)
   Set to 1 to recurse through subdirectories, 0 to not recurse.

storepaths (default 1)
   Set to 1 to store paths in the archive, 0 to strip paths from the filenames.

followlinks (default 0)
   Set to 1 to store the file that the symbolic link points to, 0 to store the link itself.

level (default 3, zip and gzip only) [1-9]
   Level of compression for zip and gzip files, 0 is none.

method (default 1, zip only)
   Set to 1 to compress files in the zip archive, 0 to store files only (no compression).

sfx (no default, zip only)
   Filename of a valid sfx header for a zip archive, NOT relative to basedir.
   SFX capability is added to a zip file by simply prepending a valid executable, so this 
      options takes the path of such a file. An example of a valid file for this would be 
      "Zip.SFX" that is included in WinRAR.

comment (no default)
   The comment added to a zip archive; may be used to set options for some sfx modules.

Example options array: $options = array('basedir' => "../example", 'overwrite' => 1);

Adding Files and Directories:
To add files use the add_files function, which takes either an array or a single 
file/path.  The * character can be used but be careful, as it is the equivalent 
of placing .* in a regular expression.
Examples: $example->add_files("htdocs");
          $example->add_files(array("test.php", "htdocs/*.txt"));

To exclude files or directories from the archive use the exclude_files function, which works 
the same as the add_files function, except it excludes any files or directories would 
otherwise be added to the archive. (eg. $example->exclude_files("*.html");)

To store files without compression (zip only), use the store_files function. This function 
works the same as add_files and exclude_files. (eg. $example->store_files("htdocs/test.txt");)

Creating and Extracting Archives:
To create an archive, call the create_archive function. (eg. $example->create_archive();)
The archive created is the one passed when creating the object.  If the file is downloaded, 
the filename sent for the download is the name passed when creating the object.

To extract an archive, call the extract_files function. (eg. $example->extract_files();)
The archive extracted is the one passed when creating the object.  If the file is extracted 
to memory, the file information is located in an array called files (eg. $example->files)

The structure of the array into which files are extracted in memory is as follows:
$files = array(
'type'=>0 for file, 2 for symbolic link, 5 for directory,
'data'=>file contents);

Any errors that occur during any process will be logged in the errors array 
(eg. $example->errors). If any serious errors occur they will report errors as
usual; only errors directly related to the creation or extraction of the archive
will be suppressed any stored in the errors array.

  Classes of Devin Doucette  >  TAR/GZIP/BZIP2/ZIP Archives  >  Download Download .zip .tar.gz  >  Support forum Support forum (29)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: TAR/GZIP/BZIP2/ZIP Archives
Base name: archive
Description: Create tar/gzip/bzip2/zip, extract tar/gzip/bzip2.
Version: 2.1
PHP version: 5.0
Licenses: BSD License
GNU General Public License (GPL)
All time users: 27744 users
All time rank: 17
Week users: 1 user
Week rank: 757 Down
  Groups   Rate classes User ratings   Dependents  
  Trackback   Applications   Files Files  

Group folder image Files and Folders Listing, accessing and manipulating files and folders View top rated classes
Group folder image Compression Data compression and file archive manipulation View top rated classes

  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Good (92%) Good (86%) Sufficient (68%) Sufficient (76%) - - Sufficient (69%) 402
Month: Not yet rated by the users

  Other classes that need this package  
Class Why it is needed Dependency
Class CSeguridad to make the final compress file Required

  Pages that reference this package  
archiv entpacken
so, ich hab jetzt auf schon mal ne ganz net klasse gefunden: TAR/GZIP/BZIP2/ZIP Archives...
entpacken von .tar archiv
Du k÷nntest dir mal bestehende Klassen anschauen:...
PHP work with TAR/GZIP/BZIP2/ZIP Archives
You can easily create all kind of backups or fast transfer between servers...
Problema download e file compressi
Grazie per il vostro aiuto, ma sto giÓ procedendo a spostare il sito su un server migliore...
Zipdateien on-the-fly erstellen mit PHP
An unserer Schule wird Moodle als LMS (Learning Management System) verwendet...

Latest pages that reference packages Latest pages that reference packages

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Plain text file archive.php Class Contains the complete script.
Accessible without login Plain text file changelog Doc. Change Log
Accessible without login Plain text file examples Example Examples
Accessible without login Plain text file readme Doc. Readme

Install with Composer Install with Composer - Download Download all files: archive.tar.gz
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.