Home  >  Article  >  Backend Development  >  PHP online packaging_Support subdirectories_PHP tutorial

PHP online packaging_Support subdirectories_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:50:49814browse

The program uses the zip extension of php. If the server supports it, you can use it ^_^. The generated zip package can be decompressed with winrar, etc., and of course it can also be decompressed with php. It will be released after a while after decompression.

$button=$_POST['button'];
if($button=="Start Packing")
{
$zip = new ZipArchive (); 
 $filename = "./".date("Y-m-d")."_".md5(time())."_jackfeng.zip"; 
 if ($zip->open( $ FILENAME, Ziparchive :: Create)! == True) {
EXIT ("Unable to create & lt; $ firename & gt; n");
}
$ files = listdir (); $files as $path) 
 { 
  $zip->addFile($path,str_replace("./","",str_replace("\","/",$path))); 
}
echo "Compression completed, total compressed: " . $zip->numFiles . "n files";
$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;
if ( is_dir($filepath) )
$files = array_merge($files, listdir($filepath));
else
array_push($files, $filepath);
}
closedir($fh);
} else {
$files = false;
}
return $files;
} 
?> 



                                                                                          




< ;a href="?">Online packaging tool

                                          ; & lt;/p & gt;
& lt; p & gt; explain: Click to start packaging. After that, it is patient to wait for the packaging to complete. According to the website file, it may take a long time. After the packaging is completed, the compressed package will be stored in the directory of the site to be packaged, named with packing time + random string of variable length + jackfeng.zip, please Log in to ftp and download.

                                                       



http://www.bkjia.com/PHPjc/319265.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/319265.htmlTechArticleThe program uses the zip extension of php. If the server supports it, you can use it ^_^, the generated zip The compressed package can be decompressed using winrar, etc., and of course you can also use php to decompress it. Excerpt from decompression...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn