Curios About Zip File using PHP

Asked By 20 points N/A Posted on -
qa-featured

Hello,

I’m doing PHP lately and I’m new to some of its functions.

I’ve encountered about This Zip File Function. Could Anyone Give me an ides on how does it really works?

And when to use Zip File Functions?

 

 

SHARE
Answered By 0 points N/A #103273

Curios About Zip File using PHP

qa-featured

Dear friend

  • Zip file function consists of bunch of functions .These function allows users in creation of compressed file, opening and reading of ZIP files with various other optins.
  • In order to use the Zip file functions,you must install the  below library on your server .

  •  Installation on Linux Systems

    • PHP 5+: For this,download the above library and the necessary extension needs to be downloaded at first.After the same,use the –with-zip=DIR configure option  which would then include Zip support.
  • Installation on Windows Systems

    • PHP 5+: For this,down load the above library at first alongwith its extension.After this is completed, inside of php.ini  file ,the php_zip.dll must be enabled.
    • For enabling any PHP extension, the PHP extension_dir setting (in the php.ini file) must be set to the directory where the PHP extensions are located. Asuitable example would be  for  extension_dir value is c:phpext.
  • Various ZIP file functions are as below.

    • zip_close(): Closes the specific ZIP file.
    • zip_entry_close(): Starts the closure of an entry in the specific  ZIP file.
    • zip_entry_compressedsize(): Returns compressed size of an entry in ZIP file.
    • zip_entry_compressionmethod():Returns compression method of an entry in ZIP file.
    • zip_entry_filesize(): Returns the actual file size of an entry in ZIP file.
    • zip_entry_name(): Returns the name of an entry in the ZIP file.
    • zip_entry_open(): Opens an entry in ZIP file for reading.
    • zip_entry_read(): Reads from an open entry in the ZIP file.
  • Example

<?php
$zip = zip_open("test1.zip");
if ($zip)
  {
  while ($zip_entry = zip_read($zip))
    {
    echo "<p>";
    echo "Name: " . zip_entry_name($zip_entry) . "<br />";
    if (zip_entry_open($zip, $zip_entry))
      {
      echo "File Contents:<br/>";
      $contents = zip_entry_read($zip_entry);
      echo "$contents<br />";
      zip_entry_close($zip_entry);
      }
    echo "</p>";
  }
zip_close($zip);
}?>

Login/Register to Answer

Related Questions