home   articles   tags   browse code   

PHP Create Zip file


 

We will make zip yyyymmdd_myfilename.txt as yyyymmdd_myfilename.zip below.

$exportfname = date("Ymd")."_myfilename.txt";
$exportzname = str_replace(".txt", ".zip", $exportfname);

if (file_exists($exportzname))
    unlink($exportzname);

$zip = new ZipArchive();
$filename = "./$exportzname";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE)
    die("cannot open $filename\n");
$zip->addFile("./$exportfname","/$exportfname");
$z_n = $zip->numFiles;
$z_s = $zip->status;
$zip->close();

echo "* numfiles: " . $z_n .  "\n";
echo "* status:" . $z_s .  "\n";
 

Tags: php
 
Web master on Jun 27th, 2009 8:49 am said:
there is also such function: http://www.phpinform.com/2009/06/27/php-classfunction-to-dynamically-create-a-zip-file-archive/
 

crhis on Aug 20th, 2010 9:00 am said:
dude thank you so much i went through tuto's for two days now and your example was so true it's unbeleivable, you rock man:)
 



 

 



Related Articles
 


home  |  privacy policy  |  terms of use  |  contact  


©2012, Zedwood.com

zedwood.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com