kencur,sikencur,aplikasi,tips dan trik, informasi,aplikasi sekolah gratis,pendidikan,aplikasi sekolah,bejalar office

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.

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

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

Download PHP Create Zip File

Comments Page 3 of 3
1 2 3


7 thoughts on “PHP Create Zip File”

  1. 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 *