Archive on the fly, Version 1.2a (alt)

Hinweis: dies ist nicht die neueste Version!

Zurück zur Übersicht

Datei: README.txt

Flocke's "Archive on the Fly"

Set of PHP classes to create archives on the fly plus a class to extract
the contents of ZIP files.

Version 1.2a - always find the latest version at
http://flocke.vssd.de/prog/code/php/aotf/

Copyright (C) 2005 Volker Siebert <flocke@vssd.de>
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

---------------------------------------------------------------------------

Flocke's "Archive on the Fly" is a small set of PHP classes to create
archives of type TAR, TGZ, and ZIP ``on the fly´´.

Simple first steps to create an archive:

1. Include the file for the type of archive you want to create:

        require_once("vs.tar.php");
    //  require_once("vs.tgz.php");
    //  require_once("vs.zip.php");

2. Create a new object of the respective class:

        $arc = new vsTarFile();
    //  $arc = new vsTgzFile();
    //  $arc = new vsZipFile();

3. Write the appropriate header, add data to your archive and write it
   to the requestor:

        $arc->headers("myfilename", "attachment");
        $arc->add_file("", ".");
        echo $arc->finish();

There are only a few public properties and functions you will use:

    var $symlink;

        Specifies how to handle symbolic links. Can be one of the following
        constants:

        VSARC_SYMLINK_AS_FILE - stores symbolic links as normal files,
                adding their content to the archive.
        VSARC_SYMLINK_OMIT - skips symbolic links, nothing is stored in
                the archive.
        VSARC_SYMLINK_AS_LINK - stores symbolic links as real links.

    function add_file($name, $filename);

        Adds a file from disk to the archive. Can handle the following cases:

        1. If FILENAME is an array, all its entries are processed
           recursively via this function, where the stored filename is
           constructed by prefixing the basename with NAME.
        2. If FILENAME is a directory, all the files and subdirectories are
           added to the archive, prefixing their names by NAME.
        3. Otherwise the file FILENAME is added to the archive, using NAME
           as its name. In this case, FILENAME could also be an internet
           link if you have URL wrappers activated.

        "add_file" checks for duplicates and will not add a file that is
        already in the archive.

    function preflush($minsize = 65536, $maxsize = 0);

        The archive class collects it's binary data in a class member
        string. This functions returns the archive data that has been
        collected so far and can already be written to the client if the
        amount of data is larger than $minsize and it will return a maximum
        of $maxsize bytes from this data and remove it from the internal
        string.

        Normally, the archive is completely created in memory and finally
        written to the client when it is finished. You can subclass and
        override the function "added_one_entry", e.g.:

        class MyZipClass extends vsZipFile {
            function added_one_entry($ftype) {
                echo $arc->preflush();
            }
        };

        Note that this is only useful for TAR and ZIP archives, because
        TGZ archives are finally compressed when they are finished.

    function finish();

        Returns the final archive data that still needs to be written to
        the client. This function can only be called once, because after
        the call the data is reset.

    function mimetype();

        Returns the MIME type for the used archive class. This is kind of
        a class function.

    function fileext();

        Returns the default file extension for the used archive class. This
        is also kind of a class function.

    function get_headers($filename = '', $disposition = '');

        Returns the default internet headers as an array, e.g.:
        $result['Content-Type'] = 'application/x-zip';

        if $filename is not empty, the default extension is added to this
        name and a 'Content-Disposition' entry is added to the headers.
        $disposition may be 'inline' or 'attachment' with a default value
        of 'attachment'.

    function headers($filename = '', $disposition = '');

        Sends the default internet headers to the client.


The file "vs.unzip.php" contains a class to extract information and data
from ZIP files if (and only if) the content is uncompressed or compressed
compatible to the zlib library.

Just include the file, create a new object of the class and open a ZIP
archive:

    $arc = new vsUnzipFile();
    $arc->open("MyOwnArchive.zip");

Now you can use the public properties:

    var $names;         // List with names and indexes
    var $directory;     // Central directory
    var $count;         // Number of entries in $names resp. $directory
    var $comment;       // ZIP file comment
    var $errors;        // Array with error messages

and the public functions:

    function &get_entry($index);

        Returns (a reference to) an entry in the central directory. The
        index can either be numeric, in this case it is translated with
        the $names array, or the filename. The return value is an array
        itself containing the following members:

        $entry['name']     Filename (directories have a trailing slash)
        $entry['gpbf']     ``General purpose bit flag´´
        $entry['method']   Compression method
        $entry['time']     Timestamp
        $entry['crc32']    CRC-32 checksum
        $entry['csize']    Compressed size
        $entry['osize']    Original (uncompressed) size
        $entry['eattr']    External attributes (bit 0x10 for directories)
        $entry['offset']   Absolute file offset of local file header
        $entry['extra']    Extra data
        $entry['data']     If set, the loaded uncompressed data

    function &get_data($index);

        Returns (a reference to) the entry's data. This is only done once,
        so you can call this function 50 times without overhead.

When you're done you just close the archive:

    $arc->close();

Flocke's Garage
Valid HTML 4.01 Transitional Valid CSS!
(C) 2005-2018 Volker Siebert.
Creative Commons-LizenzvertragDer gesamte Inhalt dieser Webseite steht unter einer Creative Commons-Lizenz (sofern nicht anders angegeben).