Provides various official and user-released code examples. For code reference, you are welcome to learn about the zip compression and decompression functions.
Function ezip ($ zip, $ hedef = ''){
$ Dirname = preg_replace ('/. zip/', '', $ zip );
$ Root = $ _ SERVER ['document _ root']. '/zip /';
// Echo $ root. $ zip;
$ Zip = zip_open ($ root. $ zip );
// Var_dump ($ zip );
@ Mkdir ($ root. $ hedef. $ dirname. '/'. $ zip_dosya );
While ($ zip_icerik = zip_read ($ zip )){
$ Zip_dosya = zip_entry_name ($ zip_icerik );
If (strpos ($ zip_dosya ,'.')){
$ Hedef_yol = $ root. $ hedef. $ dirname. '/'. $ zip_dosya;
@ Touch ($ hedef_yol );
// Echo $ hedef_yol;
$ Yeni_dosya = @ fopen ($ hedef_yol, 'W + ');
@ Fwrite ($ yeni_dosya, zip_entry_read ($ zip_icerik ));
@ Fclose ($ yeni_dosya );
// $ Yeni_dosya;
} Else {
@ Mkdir ($ root. $ hedef. $ dirname. '/'. $ zip_dosya );
// Echo $ root. $ hedef. 'x/'. $ zip_dosya;
};
};
}
// Ezip('yuol.zip ','./tr /');
Function zip ($ path ){
$ Path = preg_replace ('/\/$/', '', $ path );
Preg_match ('/\/([\ d \ D] [^ \/] *) $/', $ path, $ matches, PREG_OFFSET_CAPTURE );
$ Filename = $ matches [1] [0]. ". zip ";
// Var_dump ($ filename );
// Set_time_limit (0 );
$ Zip = new ZipArchive ();
$ Zip-> open ($ filename, ZIPARCHIVE: OVERWRITE); // return;
// Var_dump ($ path );
If (is_file ($ path )){
$ Path = preg_replace ('// \//', '/', $ path );
$ Base_dir = preg_replace ('/\/[\ d \ D] [^ \/] * $/', '/', $ path );
$ Base_dir = addcslashes ($ base_dir ,'/:');
$ Localname = preg_replace ('/'. $ base_dir. '/', '', $ path );
// Var_dump ($ localname );
$ Zip-> addFile ($ path, $ localname );
// Var_dump ($ path );
$ Zip-> close ();
Return;
} Elseif (is_dir ($ path )){
$ Path = preg_replace ('/\/[\ d \ D] [^ \/] * $/', '', $ path );
$ Base_dir = $ path. '/'; // base Directory
$ Base_dir = addcslashes ($ base_dir ,'/:');
// Var_dump ($ base_dir );
}
$ Path = preg_replace ('// \//', '/', $ path );
// Var_dump ($ path );
Function addItem ($ path, & $ zip, & $ base_dir ){
// Var_dump ($ path );
$ Handle = opendir ($ path );
// Var_dump ($ path );
While (false! ==( $ File = readdir ($ handle ))){
If ($ file! = '.') & ($ File! = '..')){
// Var_dump ($ file );
$ Ipath = $ path. '/'. $ file;
If (is_file ($ ipath) {// The entry is a file
$ Localname = preg_replace ('/'. $ base_dir. '/', '', $ ipath );
Var_dump ($ localname );
$ Zip-> addFile ($ ipath, $ localname );
// Var_dump ($ r );
} Else if (is_dir ($ ipath )){
AddItem ($ ipath, $ zip, $ base_dir );
$ Localname = preg_replace ('/'. $ base_dir. '/', '', $ ipath );
Var_dump ($ localname );
$ Zip-> addEmptyDir ($ localname );
}
// Var_dump ($ path );
}
}
}
// Var_dump ($ base_dir );
AddItem ($ path, $ zip, $ base_dir );
$ Zip-> close ();
}
Zip ('d:/wamp/www/sample/main /');
Zip.zip (1.03 KB download: 310 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB