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:

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

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 *