Results 1 to 7 of 7

Thread: How to use Zip and BZip2 in PHP?

  1. #1
    Join Date
    Aug 2006
    Posts
    209

    How to use Zip and BZip2 in PHP?

    Hello friends,
    I have used many functions in PHP programming language, but still there are many things that I am not aware of. While going through an assignment, I read about the Zip and the BZip2 in that. I was not knowing anything about it. So thought that you guys can explain me.!! So please tell me how to use Zip and BZip2 in PHP? If possible please provide some examples that may be useful for me.!!
    Blessings to you

  2. #2
    Join Date
    Aug 2006
    Posts
    235

    Re: How to use Zip and BZip2 in PHP?

    Zip : This extension provides the ability to read and write ZIP compressed archives, and access files and folders therein. The version included in PHP 4 requires the library "ZZIPlib, written by Guido Draheim, version 0.10.6 or higher.

    Bzip2 : The bzip2 functions are used to read and write seamlessly bzip2 compressed files (. Bz2). This extension uses the functions "bzip2 library written by Julian Seward. This module requires bzip2/libbzip2 version> = 1.0.x.
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  3. #3
    Join Date
    Jul 2006
    Posts
    286

    Re: How to use Zip and BZip2 in PHP?

    I have provided you with the Class ZipArchive. The following are the same :
    • ZipArchive: addEmptyDir - Adds a new folder to a Zip archive
    • ZipArchive:: addFile - Adds a file to a ZIP archive from the given path
    • ZipArchive: addFromString - Adds a file to a ZIP archive using its contents
    • ZipArchive:: close - Close the active archive
    • ZipArchive: deleteIndex - Deletes an entry from the archive using its index
    • ZipArchive: deleteName - Deletes an entry in the archive using its name
    • ZipArchive: extractTo - Extract the contents of the archive
    • ZipArchive: getArchiveComment - Returns the comment of the ZIP archive
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to use Zip and BZip2 in PHP?

    I think that you should also have a knowledge of the functions that are used for the Zip. So I thought that providing you with Zip functions would be helpful. The following are the Zip function :
    • zip_close - Close a Zip archive
    • zip_entry_close - Closes an archive file
    • zip_entry_compressedsize - Get the size of a compressed file archive
    • zip_entry_compressionmethod - Gets the compression method used on an archive folder
    • zip_entry_open - Open a file archives read
    • zip_entry_read - Reads the contents of a file in a folder
    • zip_open - Open a ZIP archive
    • zip_read - Get the next entry in a ZIP archive

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: How to use Zip and BZip2 in PHP?

    The following is the list of the Bzip2 Functions :
    • bzclose - Close a bzip2 file
    • bzcompress - Compress a string into bzip2
    • bzdecompress - bzip2 Decompress a string
    • bzflush - Force a write of all buffered data
    • bzopen - Opens a bzip2 compressed file
    • bzread - Reading binary file bzip2
    • bzwrite - Writing binary file bzip2
    • bzerrno - Returns the bzip2 error
    • bzerror - Returns the number and bzip2 error in a table

  6. #6
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to use Zip and BZip2 in PHP?

    If you want to create a Zip Archieve, you can use the following example which demonstrates how to create a Zip Archieve :
    PHP Code:
    <?php 

    $zip 
    = new ZipArchive (); 
    $filename "./demo.zip" 

    if ( 
    $zip -> open $filename ZIPARCHIVE :: CREATE )!== TRUE ) { 
    exit( 
    "Impossible d'ouvrir < $filename >\n" ); 


    $zip -> addFromString "demofilephp.txt" time (), 
    $zip -> addFromString "demofilephp2.txt" time (), 
    $zip -> addFile $thisdir "/too.php" "/demofromfile.php" ); 
    echo 
    "Name of Files : " $zip -> numFiles "\n" 
    echo 
    "status :" $zip -> status "\n" 
    $zip -> close (); 
    ?>

  7. #7
    Join Date
    Nov 2008
    Posts
    996

    Re: How to use Zip and BZip2 in PHP?

    The following example opens a temporary file and writes a test string, then displays the contents of this file. This is an example of the small bzip2 :
    PHP Code:
    <?php

    $filename 
    "/tmp/demofile.bz2";
    $str "This is a test string.\n";

    $bz bzopen($filename"w");

    bzwrite($bz$str);

    bzclose($bz);

    $bz bzopen($filename"r");

    echo 
    bzread($bz10);

    echo 
    bzread($bz);

    bzclose($bz);

    ?>

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,716,253,944.53851 seconds with 16 queries