PHP Create Zip File

PHP Create Zip File. Something needs to be considered when creating a zip file using php is already loaded or not the zlib library by php runtime. With zlib enables you to transparently read or write ZIP compressed archives and the files inside them.

The bundled PHP 4 version requires » ZZIPlib, by Guido Draheim, version 0.10.6 or later
PHP 5.2.0 or later
This extension uses the functions of » zlib by Jean-loup Gailly and Mark Adler.

PHP Create Zip File Function

To use these functions, make sure that zlib have been loaded by php runtime. Use this trick to find zlib has been loaded by php, create new file php (Ex:phpinfo.php), fill the file with this(without quote): “<?php phpinfo();?>“. Put it on the web folder then open with mozilla fire fox.

If zlib have been loaded by php, Let’ start creating the Zip file.
* Create files 1.txt, 2.txt, 3.txt, 4.txt And Create makezip.php (in the same directory with file 1.txt).
Fill the makezip.php with this:

$zip = new ZipArchive();
$filename = "";
if ($zip-&gt;open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot open"); }
$zip-&gt;addFromString("1.txt", "time create zip ".time()." #1 This is a test string added as 1.txt.\n");
$zip-&gt;addFromString("2.txt" . time(), "#2 This is a test string added as 2.txt.\n");
$zip-&gt;addFile($thisdir . "3.txt","4.txt");
// file 3.txt while be renamed to 4.txt 
echo "numfiles: " . $zip-&gt;numFiles . "<br />";
echo "status:" . $zip-&gt;status . "<br />";
echo "Directory: ".getcwd()."<br />Filename: $filename"; $zip-&gt;close();

Upload files to your web directory, then open up makezip.php with your web browser. Look at your web directory, you will see the :D


Published by

6 thoughts on “PHP Create Zip File”

  1. Angga Rizki Ramadhan berkata:

    .-= Angga Rizki Ramadhan´s last blog ..TOP 10 Foto Objek Antariksa dari ESO =-.

  2. Detox diet plan berkata:

    Thats good, your blog is cool, i like it. Thanks for the efforts my friend.
    My website is Slim fast diet.

  3. Hello, I simply wanted to take time to make a comment and say I have really enjoyed reading your site.
    My website is about best acne treatment

  4. bPapsbrabs berkata:

    iphone 4 unlock
    how to unlock iphone 4
    unlock iphone 4

  5. ChinChin berkata:

    Good job! I would say that I really enjoy reading about your post! it a great effort! Thank you for the share!

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *