Zip a folder on the server with php

字体大小: 中小 标准 ->行高大小: 标准
<? 
increase script timeout value 
ini_set("max_execution_time", 300); 
// create object 
$zip = new ZipArchive(); 
// open archive 
if ($zip->open("my-archive.zip", ZIPARCHIVE::CREATE) !== TRUE) { 
die ("Could not open archive"); 
} 
// initialize an iterator 
// pass it the directory to be processed 
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("app/")); 
// iterate over the directory 
// add each file found to the archive 
foreach ($iterator as $key=>$value) { 
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key"); 
} 
// close and save archive 
$zip->close(); 
echo "Archive created successfully."; 
?>

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/67220.html