1111 * @version 0.1.0
1212 */
1313define ('VERSION ' , '0.1.0 ' );
14-
1514$ timestart = microtime (TRUE );
1615$ GLOBALS ['status ' ] = array ();
17-
1816$ unzipper = new Unzipper ;
1917if (isset ($ _POST ['dounzip ' ])) {
2018 //check if an archive was selected for unzipping
2119 $ archive = isset ($ _POST ['zipfile ' ]) ? strip_tags ($ _POST ['zipfile ' ]) : '' ;
2220 $ destination = isset ($ _POST ['extpath ' ]) ? strip_tags ($ _POST ['extpath ' ]) : '' ;
2321 $ unzipper ->prepareExtraction ($ archive , $ destination );
2422}
25-
2623if (isset ($ _POST ['dozip ' ])) {
2724 $ zippath = !empty ($ _POST ['zippath ' ]) ? strip_tags ($ _POST ['zippath ' ]) : '. ' ;
2825 // Resulting zipfile e.g. zipper--2016-07-23--11-55.zip
2926 $ zipfile = 'zipper- ' . date ("Y-m-d--H-i " ) . '.zip ' ;
3027 Zipper::zipDir ($ zippath , $ zipfile );
3128}
32-
3329$ timeend = microtime (TRUE );
3430$ time = $ timeend - $ timestart ;
35-
3631/**
3732 * Class Unzipper
3833 */
3934class Unzipper {
4035 public $ localdir = '. ' ;
4136 public $ zipfiles = array ();
42-
4337 public function __construct () {
44-
4538 //read directory and pick .zip and .gz files
4639 if ($ dh = opendir ($ this ->localdir )) {
4740 while (($ file = readdir ($ dh )) !== FALSE ) {
@@ -53,16 +46,14 @@ public function __construct() {
5346 }
5447 }
5548 closedir ($ dh );
56-
5749 if (!empty ($ this ->zipfiles )) {
58- $ GLOBALS ['status ' ] = array ('info ' => '.zip oder .gz oder .rar Dateien gefunden, bereit zum entpacken! ' );
50+ $ GLOBALS ['status ' ] = array ('info ' => '.zip or .gz or .rar files found, ready for extraction ' );
5951 }
6052 else {
61- $ GLOBALS ['status ' ] = array ('info ' => 'Keine .zip oder .gz oder . rar Dateien gefunden. Deshalb nur die Zipping-Funktionalität verfügbar . ' );
53+ $ GLOBALS ['status ' ] = array ('info ' => 'No .zip or .gz or rar files found. So only zipping functionality available . ' );
6254 }
6355 }
6456 }
65-
6657 /**
6758 * Prepare and check zipfile for extraction.
6859 *
@@ -86,7 +77,6 @@ public function prepareExtraction($archive, $destination) {
8677 self ::extract ($ archive , $ extpath );
8778 }
8879 }
89-
9080 /**
9181 * Checks file extension and calls suitable extractor functions.
9282 *
@@ -106,9 +96,7 @@ public static function extract($archive, $destination) {
10696 self ::extractRarArchive ($ archive , $ destination );
10797 break ;
10898 }
109-
11099 }
111-
112100 /**
113101 * Decompress/extract a zip archive using ZipArchive.
114102 *
@@ -118,29 +106,26 @@ public static function extract($archive, $destination) {
118106 public static function extractZipArchive ($ archive , $ destination ) {
119107 // Check if webserver supports unzipping.
120108 if (!class_exists ('ZipArchive ' )) {
121- $ GLOBALS ['status ' ] = array ('error ' => 'Error: Ihre PHP-Version unterstützt die Fähigkeit zum entpacken von Archiven nicht . ' );
109+ $ GLOBALS ['status ' ] = array ('error ' => 'Error: Your PHP version does not support unzip functionality . ' );
122110 return ;
123111 }
124-
125112 $ zip = new ZipArchive ;
126-
127113 // Check if archive is readable.
128114 if ($ zip ->open ($ archive ) === TRUE ) {
129115 // Check if destination is writable
130116 if (is_writeable ($ destination . '/ ' )) {
131117 $ zip ->extractTo ($ destination );
132118 $ zip ->close ();
133- $ GLOBALS ['status ' ] = array ('success ' => 'Dateien erfolgreich entpackt. ' );
119+ $ GLOBALS ['status ' ] = array ('success ' => 'Files unzipped successfully ' );
134120 }
135121 else {
136- $ GLOBALS ['status ' ] = array ('error ' => 'Error: Verzeichnis vom Webserver nicht beschreibbar . ' );
122+ $ GLOBALS ['status ' ] = array ('error ' => 'Error: Directory not writeable by webserver . ' );
137123 }
138124 }
139125 else {
140- $ GLOBALS ['status ' ] = array ('error ' => 'Error: Das .zip-Archiv ist nicht lesbar . ' );
126+ $ GLOBALS ['status ' ] = array ('error ' => 'Error: Cannot read .zip archive . ' );
141127 }
142128 }
143-
144129 /**
145130 * Decompress a .gz File.
146131 *
@@ -150,30 +135,25 @@ public static function extractZipArchive($archive, $destination) {
150135 public static function extractGzipFile ($ archive , $ destination ) {
151136 // Check if zlib is enabled
152137 if (!function_exists ('gzopen ' )) {
153- $ GLOBALS ['status ' ] = array ('error ' => 'Error: Ihr PHP hat keine zlib-Unterstützung aktiviert! ' );
138+ $ GLOBALS ['status ' ] = array ('error ' => 'Error: Your PHP has no zlib support enabled. ' );
154139 return ;
155140 }
156-
157141 $ filename = pathinfo ($ archive , PATHINFO_FILENAME );
158142 $ gzipped = gzopen ($ archive , "rb " );
159143 $ file = fopen ($ filename , "w " );
160-
161144 while ($ string = gzread ($ gzipped , 4096 )) {
162145 fwrite ($ file , $ string , strlen ($ string ));
163146 }
164147 gzclose ($ gzipped );
165148 fclose ($ file );
166-
167149 // Check if file was extracted.
168150 if (file_exists ($ destination . '/ ' . $ filename )) {
169- $ GLOBALS ['status ' ] = array ('success ' => 'Datei erfolgreich entpackt . ' );
151+ $ GLOBALS ['status ' ] = array ('success ' => 'File unzipped successfully . ' );
170152 }
171153 else {
172- $ GLOBALS ['status ' ] = array ('error ' => 'Fehler beim entpacken der Datei . ' );
154+ $ GLOBALS ['status ' ] = array ('error ' => 'Error unzipping file . ' );
173155 }
174-
175156 }
176-
177157 /**
178158 * Decompress/extract a Rar archive using RarArchive.
179159 *
@@ -183,7 +163,7 @@ public static function extractGzipFile($archive, $destination) {
183163 public static function extractRarArchive ($ archive , $ destination ) {
184164 // Check if webserver supports unzipping.
185165 if (!class_exists ('RarArchive ' )) {
186- $ GLOBALS ['status ' ] = array ('error ' => 'Error: Ihre PHP-Version unterstützt keine .rar-Funktionalitäten <a class="info" href="http://php.net/manual/en/rar.installation.php" target="_blank">How to install RarArchive</a> ' );
166+ $ GLOBALS ['status ' ] = array ('error ' => 'Error: Your PHP version does not support .rar archive functionality. <a class="info" href="http://php.net/manual/en/rar.installation.php" target="_blank">How to install RarArchive</a> ' );
187167 return ;
188168 }
189169 // Check if archive is readable.
@@ -195,19 +175,17 @@ public static function extractRarArchive($archive, $destination) {
195175 $ entry ->extract ($ destination );
196176 }
197177 $ rar ->close ();
198- $ GLOBALS ['status ' ] = array ('success ' => 'Dateien erfolgreich extrahiert . ' );
178+ $ GLOBALS ['status ' ] = array ('success ' => 'Files extracted successfully . ' );
199179 }
200180 else {
201- $ GLOBALS ['status ' ] = array ('error ' => 'Error: Verzeichnis vom Webserver nicht beschreibbar . ' );
181+ $ GLOBALS ['status ' ] = array ('error ' => 'Error: Directory not writeable by webserver . ' );
202182 }
203183 }
204184 else {
205- $ GLOBALS ['status ' ] = array ('error ' => 'Error: Das .rar-Archiv kann nicht gelesen werden! ' );
185+ $ GLOBALS ['status ' ] = array ('error ' => 'Error: Cannot read .rar archive. ' );
206186 }
207187 }
208-
209188}
210-
211189/**
212190 * Class Zipper
213191 *
@@ -229,14 +207,12 @@ class Zipper {
229207 */
230208 private static function folderToZip ($ folder , &$ zipFile , $ exclusiveLength ) {
231209 $ handle = opendir ($ folder );
232-
233210 while (FALSE !== $ f = readdir ($ handle )) {
234211 // Check for local/parent path or zipping file itself and skip.
235212 if ($ f != '. ' && $ f != '.. ' && $ f != basename (__FILE__ )) {
236213 $ filePath = "$ folder/ $ f " ;
237214 // Remove prefix from file path before add to zip.
238215 $ localPath = substr ($ filePath , $ exclusiveLength );
239-
240216 if (is_file ($ filePath )) {
241217 $ zipFile ->addFile ($ filePath , $ localPath );
242218 }
@@ -249,7 +225,6 @@ private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
249225 }
250226 closedir ($ handle );
251227 }
252-
253228 /**
254229 * Zip a folder (including itself).
255230 * Usage:
@@ -265,7 +240,6 @@ public static function zipDir($sourcePath, $outZipPath) {
265240 $ pathInfo = pathinfo ($ sourcePath );
266241 $ parentPath = $ pathInfo ['dirname ' ];
267242 $ dirName = $ pathInfo ['basename ' ];
268-
269243 $ z = new ZipArchive ();
270244 $ z ->open ($ outZipPath , ZipArchive::CREATE );
271245 $ z ->addEmptyDir ($ dirName );
@@ -276,40 +250,47 @@ public static function zipDir($sourcePath, $outZipPath) {
276250 self ::folderToZip ($ sourcePath , $ z , strlen ("$ parentPath/ " ));
277251 }
278252 $ z ->close ();
279-
280- $ GLOBALS ['status ' ] = array ('success ' => 'Archiv erfolgreich erstellt ' . $ outZipPath );
253+ $ GLOBALS ['status ' ] = array ('success ' => 'Successfully created archive ' . $ outZipPath );
281254 }
282255}
283256?>
284257
285258<!DOCTYPE html>
286- <html lang="de" >
259+ <html>
287260<head>
288261 <title>File Unzipper + Zipper</title>
289262 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
263+ <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet">
290264 <style type="text/css">
291265 <!--
292266 body {
293- font-family: Arial , sans-serif;
267+ font-family: 'Ubuntu' , sans-serif;
294268 line-height: 150%;
269+ background-color: #cccccc;
295270 }
296-
297271 label {
298272 display: block;
299273 margin-top: 20px;
300274 }
301-
302275 fieldset {
303276 border: 0;
304277 background-color: #EEE;
305278 margin: 10px 0 10px 0;
306279 }
307-
280+ .wrapper {
281+ width: 960px;
282+ margin: auto;
283+ margin-top: 82px;
284+ margin-bottom: 115px;
285+ box-shadow: 0px 0px 280px rgba(0, 0, 0, 0.3);
286+ }
287+ .innerwrapper {
288+ padding: 15px;
289+ }
308290 .select {
309291 padding: 5px;
310292 font-size: 110%;
311293 }
312-
313294 .status {
314295 margin: 0;
315296 margin-bottom: 20px;
@@ -318,41 +299,34 @@ public static function zipDir($sourcePath, $outZipPath) {
318299 background: #EEE;
319300 border: 1px dotted #DDD;
320301 }
321-
322302 .status--ERROR {
323303 background-color: red;
324304 color: white;
325305 font-size: 120%;
326306 }
327-
328307 .status--SUCCESS {
329308 background-color: green;
330309 font-weight: bold;
331310 color: white;
332311 font-size: 120%
333312 }
334-
335313 .small {
336314 font-size: 0.7rem;
337315 font-weight: normal;
338316 }
339-
340317 .version {
341318 font-size: 80%;
342319 }
343-
344320 .form-field {
345321 border: 1px solid #AAA;
346322 padding: 8px;
347323 width: 280px;
348324 }
349-
350325 .info {
351326 margin-top: 0;
352327 font-size: 80%;
353328 color: #777;
354329 }
355-
356330 .submit {
357331 background-color: #378de5;
358332 border: 0;
@@ -362,43 +336,53 @@ public static function zipDir($sourcePath, $outZipPath) {
362336 margin: 20px 0 20px 0;
363337 text-decoration: none;
364338 }
365-
366339 .submit:hover {
367340 background-color: #2c6db2;
368341 cursor: pointer;
369342 }
343+
344+ @media (max-width: 960px) {
345+ .wrapper {
346+ width: 100%;
347+ margin: auto;
348+ }
349+ }
370350 -->
371351 </style>
372352</head>
373353<body>
374- <p class="status status--<?php echo strtoupper (key ($ GLOBALS ['status ' ])); ?> ">
375- Status: <?php echo reset ($ GLOBALS ['status ' ]); ?> <br/>
376- <span class="small">Benötigte Zeit: <?php echo $ time ; ?> Sekunden</span>
377- </p>
378- <form action="" method="POST">
379- <fieldset>
380- <h1>Archiv Unzipper</h1>
381- <label for="zipfile">Wählen Sie ein .rar, .zip oder .gz-Archiv das sie entpacken wollen:</label>
382- <select name="zipfile" size="1" class="select">
383- <?php foreach ($ unzipper ->zipfiles as $ zip ) {
384- echo "<option> $ zip</option> " ;
385- }
386- ?>
387- </select>
388- <label for="extpath">Pfad in den entpackt werden soll (Optional):</label>
389- <input type="text" name="extpath" class="form-field" />
390- <p class="info">Den gewünschten Pfad ohne Slash am Anfang oder Ende eingeben (z.B. "meinPfad"). Wenn das Feld leergelassen wird dann wird das Archiv im selben Pfad entpackt.</p>
391- <input type="submit" name="dounzip" class="submit" value="Entpacken"/>
392- </fieldset>
393-
394- <fieldset>
395- <h1>Archiv Zipper</h1>
396- <label for="zippath">Pfad den Sie zippen wollen (Optional):</label>
397- <input type="text" name="zippath" class="form-field" />
398- <p class="info">Den gewünschten Pfad ohne Slash am Anfang oder Ende eingeben (z.B. "meinPfad"). Wenn das Feld leergelassen wird dann wird der aktuelle Pfad verwendet</p>
399- <input type="submit" name="dozip" class="submit" value="Packen"/>
400- </fieldset>
401- </form>
402- <p class="version">Unzipper Version: <?php echo VERSION ; ?> </p>
354+ <div class="wrapper">
355+ <div class="innerwrapper">
356+ <p class="status status--<?php echo strtoupper (key ($ GLOBALS ['status ' ])); ?> ">
357+ Status: <?php echo reset ($ GLOBALS ['status ' ]); ?> <br/>
358+ <span class="small">Benötigte Zeit: <?php echo $ time ; ?> Sekunden</span>
359+ </p>
360+ <form action="" method="POST">
361+ <fieldset>
362+ <h1>Archiv Unzipper</h1>
363+ <label for="zipfile">Wählen Sie ein .rar, .zip oder .gz-Archiv das sie entpacken wollen:</label>
364+ <select name="zipfile" size="1" class="select">
365+ <?php foreach ($ unzipper ->zipfiles as $ zip ) {
366+ echo "<option> $ zip</option> " ;
367+ }
368+ ?>
369+ </select>
370+ <label for="extpath">Pfad zum Entpacken (Optional):</label>
371+ <input type="text" name="extpath" class="form-field" />
372+ <p class="info">Den gewünschten Pfad ohne Slash am Anfang oder Ende eingeben (z.B. "meinPfad"). Wenn das Feld leergelassen wird dann wird das Archiv im selben Pfad entpackt.</p>
373+ <input type="submit" name="dounzip" class="submit" value="Entpacken"/>
374+ </fieldset>
375+
376+ <fieldset>
377+ <h1>Archiv Zipper</h1>
378+ <label for="zippath">Pfad den Sie zippen wollen (Optional):</label>
379+ <input type="text" name="zippath" class="form-field" />
380+ <p class="info">Den gewünschten Pfad ohne Slash am Anfang oder Ende eingeben (z.B. "meinPfad"). Wenn das Feld leergelassen wird dann wird der aktuelle Pfad verwendet</p>
381+ <input type="submit" name="dozip" class="submit" value="Packen"/>
382+ </fieldset>
383+ </form>
384+ <p class="version">Unzipper Version: <?php echo VERSION ; ?> </p>
385+ </div>
386+ </div>
403387</body>
404388</html>
0 commit comments