Home > Article > Backend Development > How to turn off the background program in Apple ios7 PHP online packaging program source code
Realize the packaging function ~ easy and convenient! Although the compression ratio is a little worse than winrar, it doesn't matter. After all, it is only packaged for downloading. It saves you the trouble of going to the server to package the site. If the server is not your own, it will be more troublesome. Ask others to help package the package. Copy the code
The code is as follows:
//php compress the directory into a zip package
//Author: Xiaofeng
$button=$_POST['button'];
if($button=="Start packaging")
{
$ zip = new ZipArchive();
$filename = "./".date("Y-m-d")."_".md5(time())."_jackfeng.zip";
if ($zip->open( $filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("Cannot create <$filename>n");
}
$files = listdir();
foreach($files as $path)
{ -$ Zip-& gt; addfile ($ PATH, Str_replace ("./", "", Str_replace ("\", "/", $ PATH)); . $zip->numFiles . "files n";
$zip->close();
}
Function listdir($start_dir='.') {
$files = array();
if (is_dir ($start_dir)) {
$fh = opendir($start_dir);
while (($file = readdir($fh)) !== false) {
if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
$filepath = $start_dir. '/' . $file; listdir($filepath)); ;
}
return $files;
}
?> ;