| @@ -19,10 +19,10 @@ discard block | ||
| 19 | 19 | */ | 
| 20 | 20 | public $client; | 
| 21 | 21 | |
| 22 | -    static public function init(){ | |
| 22 | +    static public function init() { | |
| 23 | 23 | $gateway = new self(); | 
| 24 | 24 | |
| 25 | - $gateway->client = new ZipArchive(); | |
| 25 | + $gateway->client = new ZipArchive(); | |
| 26 | 26 | return $gateway; | 
| 27 | 27 | } | 
| 28 | 28 | |
| @@ -33,29 +33,29 @@ discard block | ||
| 33 | 33 | * @author: Tinymeng <[email protected]> | 
| 34 | 34 | * @time: 2022/4/27 9:26 | 
| 35 | 35 | */ | 
| 36 | -    public function open($filename,$Fromfilename=null){ | |
| 37 | -        if (!empty($filename)){ | |
| 36 | +    public function open($filename, $Fromfilename = null) { | |
| 37 | +        if (!empty($filename)) { | |
| 38 | 38 | $this->setFileName($filename); | 
| 39 | - if(!$this->client->open($this->fileName, ZipArchive::CREATE)) | |
| 39 | + if (!$this->client->open($this->fileName, ZipArchive::CREATE)) | |
| 40 | 40 | return 'File open failed'; | 
| 41 | 41 | } | 
| 42 | -        if(!empty($Fromfilename)){ | |
| 43 | -            if(is_dir($Fromfilename)){ | |
| 42 | +        if (!empty($Fromfilename)) { | |
| 43 | +            if (is_dir($Fromfilename)) { | |
| 44 | 44 | $list_dir = scandir($Fromfilename); | 
| 45 | -                for($i=2;$i<count($list_dir);$i++){ | |
| 46 | -                    if(is_dir($Fromfilename.'/'.$list_dir[$i])){ | |
| 45 | +                for ($i = 2; $i < count($list_dir); $i++) { | |
| 46 | +                    if (is_dir($Fromfilename.'/'.$list_dir[$i])) { | |
| 47 | 47 |                          $this->client->addGlob($Fromfilename.'/'.$list_dir[$i].'/*.*', 0, array('add_path' => $Fromfilename.'/'.$list_dir[$i].'/', 'remove_path' => $Fromfilename.'/'.$list_dir[$i])); | 
| 48 | 48 | $list_chr = scandir($Fromfilename.'/'.$list_dir[$i]); | 
| 49 | -                        for($j=2;$j<count($list_chr);$j++){ | |
| 50 | -                            if(is_dir($Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j])){ | |
| 49 | +                        for ($j = 2; $j < count($list_chr); $j++) { | |
| 50 | +                            if (is_dir($Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j])) { | |
| 51 | 51 | echo $list_chr[$j]; | 
| 52 | -                                $this->open('',$Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j]); | |
| 52 | +                                $this->open('', $Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j]); | |
| 53 | 53 | } | 
| 54 | 54 | } | 
| 55 | 55 | } | 
| 56 | 56 | } | 
| 57 | -            }else{ | |
| 58 | - $this->client->addFile ($Fromfilename); | |
| 57 | +            } else { | |
| 58 | + $this->client->addFile($Fromfilename); | |
| 59 | 59 | } | 
| 60 | 60 | } | 
| 61 | 61 | return $this; | 
| @@ -68,9 +68,9 @@ discard block | ||
| 68 | 68 | * @author: Tinymeng <[email protected]> | 
| 69 | 69 | * @time: 2022/4/27 9:26 | 
| 70 | 70 | */ | 
| 71 | -    private function setFileName($filename){ | |
| 72 | -        if(!preg_match('/zip/m', $filename)){ | |
| 73 | -            $filename = $filename.'-'.date('Ymd').rand(111,999).'.zip'; | |
| 71 | +    private function setFileName($filename) { | |
| 72 | +        if (!preg_match('/zip/m', $filename)) { | |
| 73 | +            $filename = $filename.'-'.date('Ymd').rand(111, 999).'.zip'; | |
| 74 | 74 | } | 
| 75 | 75 | $this->fileName = $filename; | 
| 76 | 76 | return $filename; | 
| @@ -82,7 +82,7 @@ discard block | ||
| 82 | 82 | * @author: Tinymeng <[email protected]> | 
| 83 | 83 | * @time: 2022/4/27 9:50 | 
| 84 | 84 | */ | 
| 85 | -    public function getFileName(){ | |
| 85 | +    public function getFileName() { | |
| 86 | 86 | return $this->fileName; | 
| 87 | 87 | } | 
| 88 | 88 | |
| @@ -94,8 +94,8 @@ discard block | ||
| 94 | 94 | * @author: Tinymeng <[email protected]> | 
| 95 | 95 | * @time: 2022/4/27 9:31 | 
| 96 | 96 | */ | 
| 97 | -    public function addFileContent($file_name,$content){ | |
| 98 | - $this->client->addFromString($file_name,$content); | |
| 97 | +    public function addFileContent($file_name, $content) { | |
| 98 | + $this->client->addFromString($file_name, $content); | |
| 99 | 99 | return $this; | 
| 100 | 100 | } | 
| 101 | 101 | |
| @@ -107,8 +107,8 @@ discard block | ||
| 107 | 107 | * @author: Tinymeng <[email protected]> | 
| 108 | 108 | * @time: 2022/4/27 9:31 | 
| 109 | 109 | */ | 
| 110 | -    public function addFile($file_name,$content){ | |
| 111 | - $this->client->addFromString($file_name,$content); | |
| 110 | +    public function addFile($file_name, $content) { | |
| 111 | + $this->client->addFromString($file_name, $content); | |
| 112 | 112 | return $this; | 
| 113 | 113 | } | 
| 114 | 114 | |
| @@ -116,7 +116,7 @@ discard block | ||
| 116 | 116 | * 文件下载 | 
| 117 | 117 | * @return void | 
| 118 | 118 | */ | 
| 119 | -    public function download(){ | |
| 119 | +    public function download() { | |
| 120 | 120 | $this->client->finish(); | 
| 121 | 121 | } | 
| 122 | 122 | |
| @@ -128,17 +128,17 @@ discard block | ||
| 128 | 128 | * @author: Tinymeng <[email protected]> | 
| 129 | 129 | * @time: 2022/4/27 9:38 | 
| 130 | 130 | */ | 
| 131 | -    public function unzip($filename,$dir){ | |
| 132 | - if(!file_exists($filename)) | |
| 131 | +    public function unzip($filename, $dir) { | |
| 132 | + if (!file_exists($filename)) | |
| 133 | 133 | return 'File does not exist'; | 
| 134 | - if(!$this->client->open($filename)) | |
| 134 | + if (!$this->client->open($filename)) | |
| 135 | 135 | return 'File open failed'; | 
| 136 | -        if(!is_dir($dir)){ | |
| 137 | - mkdir($dir,775); | |
| 138 | -        }else{ | |
| 136 | +        if (!is_dir($dir)) { | |
| 137 | + mkdir($dir, 775); | |
| 138 | +        } else { | |
| 139 | 139 | return 'Dir mk failed'; | 
| 140 | 140 | } | 
| 141 | - if(!$this->client->extractTo($dir)) | |
| 141 | + if (!$this->client->extractTo($dir)) | |
| 142 | 142 | return 'File unzip failed'; | 
| 143 | 143 | return $this; | 
| 144 | 144 | } | 
| @@ -36,8 +36,9 @@ discard block | ||
| 36 | 36 |      public function open($filename,$Fromfilename=null){ | 
| 37 | 37 |          if (!empty($filename)){ | 
| 38 | 38 | $this->setFileName($filename); | 
| 39 | - if(!$this->client->open($this->fileName, ZipArchive::CREATE)) | |
| 40 | - return 'File open failed'; | |
| 39 | +            if(!$this->client->open($this->fileName, ZipArchive::CREATE)) { | |
| 40 | + return 'File open failed'; | |
| 41 | + } | |
| 41 | 42 | } | 
| 42 | 43 |          if(!empty($Fromfilename)){ | 
| 43 | 44 |              if(is_dir($Fromfilename)){ | 
| @@ -54,7 +55,7 @@ discard block | ||
| 54 | 55 | } | 
| 55 | 56 | } | 
| 56 | 57 | } | 
| 57 | -            }else{ | |
| 58 | +            } else{ | |
| 58 | 59 | $this->client->addFile ($Fromfilename); | 
| 59 | 60 | } | 
| 60 | 61 | } | 
| @@ -129,17 +130,20 @@ discard block | ||
| 129 | 130 | * @time: 2022/4/27 9:38 | 
| 130 | 131 | */ | 
| 131 | 132 |      public function unzip($filename,$dir){ | 
| 132 | - if(!file_exists($filename)) | |
| 133 | - return 'File does not exist'; | |
| 134 | - if(!$this->client->open($filename)) | |
| 135 | - return 'File open failed'; | |
| 133 | +        if(!file_exists($filename)) { | |
| 134 | + return 'File does not exist'; | |
| 135 | + } | |
| 136 | +        if(!$this->client->open($filename)) { | |
| 137 | + return 'File open failed'; | |
| 138 | + } | |
| 136 | 139 |          if(!is_dir($dir)){ | 
| 137 | 140 | mkdir($dir,775); | 
| 138 | -        }else{ | |
| 141 | +        } else{ | |
| 139 | 142 | return 'Dir mk failed'; | 
| 140 | 143 | } | 
| 141 | - if(!$this->client->extractTo($dir)) | |
| 142 | - return 'File unzip failed'; | |
| 144 | +        if(!$this->client->extractTo($dir)) { | |
| 145 | + return 'File unzip failed'; | |
| 146 | + } | |
| 143 | 147 | return $this; | 
| 144 | 148 | } | 
| 145 | 149 | |