Save the code in php format and then drop it under your site to open it ...... Package functions ~ Easy and convenient! Although the compression ratio is a little worse than winrar, it does not matter. after all, it is only packaged for download.
It saves you the trouble to package your site on the server. if the server is not your own, you have to ask someone to help you package.
The code is as follows:
// Compress the php directory into a zip package
// Author: Xiao Feng
$ Button = $ _ POST ['click'];
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-> addFile ($ path, str_replace ("./", "", str_replace ("\", "/", $ path )));
}
Echo "compressed, compressed:". $ zip-> numFiles. "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;
}
?>
Online packaging tools