- 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)) {//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 ();
- }
- Calling methods
- Zip (' unzipped directory ');
Copy Code
|