Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

Commit 3a4172e

Browse files
updating status of classes
1 parent fe0f924 commit 3a4172e

File tree

4 files changed

+211
-200
lines changed

4 files changed

+211
-200
lines changed

resources/classes/explorer.php

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
<?php
2-
class Explorer {
32

4-
public function createExplorer($exppath) {
5-
$ordner = $exppath;
6-
$alledateien = scandir($ordner);
7-
8-
foreach ($alledateien as $datei) {
9-
$dateiinfo = pathinfo($ordner."/".$datei);
10-
$size = ceil(filesize($ordner."/".$datei)/1024);
11-
if ($datei != "." && $datei != ".." && $datei != "_notes" && $bildinfo['basename'] != "Thumbs.db") {
3+
class Explorer
4+
{
5+
public function createExplorer($exppath)
6+
{
7+
$ordner = $exppath;
8+
$alledateien = scandir($ordner);
9+
if (is_dir($ordner) == false) {
10+
$_SESSION['status'] = array('error' => 'Error: Verzeichnis nicht lesbar!');
11+
} else {
12+
$_SESSION['status'] = array('success' => 'Verzeichnis erfolgreich geöffnet!');
13+
foreach ($alledateien as $datei) {
14+
$dateiinfo = pathinfo($ordner.'/'.$datei);
15+
$size = ceil(filesize($ordner.'/'.$datei) / 1024);
16+
if ($datei != '.' && $datei != '..' && $datei != '_notes' && $bildinfo['basename'] != 'Thumbs.db') {
1217

1318
//Bildtypen sammeln
14-
$bildtypen= array("jpg", "jpeg", "gif", "png");
19+
$bildtypen = array('jpg', 'jpeg', 'gif', 'png');
1520

1621
//Dateien nach Typ prüfen, in dem Fall nach Endungen für Bilder filtern
17-
if(in_array($dateiinfo['extension'],$bildtypen))
18-
{ echo (
22+
if (in_array($dateiinfo['extension'], $bildtypen)) {
23+
echo
1924
"<div class='galerie'>
20-
<a href='" . $dateiinfo['dirname']."/".$dateiinfo['basename'] . "'>
21-
<img src='" . $dateiinfo['dirname']."/".$dateiinfo['basename'] . "' width='140' alt='Vorschau' /></a>
22-
<span>" . $dateiinfo['filename'] . "(" . $size . " kb)</span>
23-
</div>"
24-
);
25-
25+
<a href='" .$dateiinfo['dirname'].'/'.$dateiinfo['basename']."'>
26+
<img src='" .$dateiinfo['dirname'].'/'.$dateiinfo['basename']."' width='140' alt='Vorschau' /></a>
27+
<span>" .$dateiinfo['filename'].'('.$size.' kb)</span>
28+
</div>'
29+
;
2630

2731
// wenn keine Bildeindung dann normale Liste für Dateien ausgeben
28-
} else { echo ("
32+
} else {
33+
echo "
2934
<div class='file'>
30-
<a href='" . $dateiinfo['dirname'] . "/" .$dateiinfo['basename'] . "'>&raquo; " .$dateiinfo['filename'] . " </a> (" . $dateiinfo['extension'] . " | " . $size. "kb)
31-
</div>");
32-
}
33-
34-
};
35-
};
36-
}
35+
<a href='" .$dateiinfo['dirname'].'/'.$dateiinfo['basename']."'>&raquo; ".$dateiinfo['filename'].' </a> ('.$dateiinfo['extension'].' | '.$size.'kb)
36+
</div>';
37+
}
38+
}
39+
}
40+
}
41+
}
3742
}
38-
?>

resources/classes/unzip.php

Lines changed: 85 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
11
<?php
2-
class Unzipper {
3-
public $localdir = '.';
4-
public $zipfiles = array();
5-
public function __construct() {
6-
//read directory and pick .zip and .gz files
2+
3+
class Unzipper
4+
{
5+
public $localdir = '.';
6+
public $zipfiles = array();
7+
public function __construct()
8+
{
9+
//read directory and pick .zip and .gz files
710
if ($dh = opendir($this->localdir)) {
8-
while (($file = readdir($dh)) !== FALSE) {
9-
if (pathinfo($file, PATHINFO_EXTENSION) === 'zip'
11+
while (($file = readdir($dh)) !== false) {
12+
if (pathinfo($file, PATHINFO_EXTENSION) === 'zip'
1013
|| pathinfo($file, PATHINFO_EXTENSION) === 'gz'
1114
|| pathinfo($file, PATHINFO_EXTENSION) === 'rar'
1215
) {
13-
$this->zipfiles[] = $file;
16+
$this->zipfiles[] = $file;
17+
}
1418
}
15-
}
16-
closedir($dh);
17-
if (!empty($this->zipfiles)) {
18-
$GLOBALS['status'] = array('info' => '.zip, .gz oder .rar Dateien gefunden, bereit zum entpacken.');
19-
}
20-
else {
21-
$GLOBALS['status'] = array('info' => 'Keine .zip oder .gz oder rar Dateien gefunden.');
22-
}
19+
closedir($dh);
20+
/*
21+
if (!empty($this->zipfiles)) {
22+
$_SESSION['status'] = array('info' => '.zip, .gz oder .rar Dateien gefunden, bereit zum entpacken.');
23+
} else {
24+
$_SESSION['status'] = array('info' => 'Keine .zip oder .gz oder rar Dateien gefunden.');
25+
}*/
26+
}
2327
}
24-
}
2528
/**
2629
* Prepare and check zipfile for extraction.
2730
*
2831
* @param $archive
2932
* @param $destination
3033
*/
31-
public function prepareExtraction($archive, $destination) {
32-
// Determine paths.
34+
public function prepareExtraction($archive, $destination)
35+
{
36+
// Determine paths.
3337
if (empty($destination)) {
34-
$extpath = $this->localdir;
35-
}
36-
else {
37-
$extpath = $this->localdir . '/' . $destination;
38+
$extpath = $this->localdir;
39+
} else {
40+
$extpath = $this->localdir.'/'.$destination;
3841
// todo move this to extraction function
3942
if (!is_dir($extpath)) {
40-
mkdir($extpath);
43+
mkdir($extpath);
4144
}
4245
}
4346
//allow only local existing archives to extract
4447
if (in_array($archive, $this->zipfiles)) {
45-
self::extract($archive, $extpath);
48+
self::extract($archive, $extpath);
4649
}
4750
}
4851
/**
@@ -51,9 +54,10 @@ public function prepareExtraction($archive, $destination) {
5154
* @param $archive
5255
* @param $destination
5356
*/
54-
public static function extract($archive, $destination) {
55-
$ext = pathinfo($archive, PATHINFO_EXTENSION);
56-
switch ($ext) {
57+
public static function extract($archive, $destination)
58+
{
59+
$ext = pathinfo($archive, PATHINFO_EXTENSION);
60+
switch ($ext) {
5761
case 'zip':
5862
self::extractZipArchive($archive, $destination);
5963
break;
@@ -71,27 +75,27 @@ public static function extract($archive, $destination) {
7175
* @param $archive
7276
* @param $destination
7377
*/
74-
public static function extractZipArchive($archive, $destination) {
75-
// Check if webserver supports unzipping.
78+
public static function extractZipArchive($archive, $destination)
79+
{
80+
// Check if webserver supports unzipping.
7681
if (!class_exists('ZipArchive')) {
77-
$GLOBALS['status'] = array('error' => 'Fehler: Ihre PHP-Version unterstützt keine unzip-Fähigkeiten.');
78-
return;
82+
$_SESSION['status'] = array('error' => 'Fehler: Ihre PHP-Version unterstützt keine unzip-Fähigkeiten.');
83+
84+
return;
7985
}
80-
$zip = new ZipArchive;
86+
$zip = new ZipArchive();
8187
// Check if archive is readable.
82-
if ($zip->open($archive) === TRUE) {
83-
// Check if destination is writable
84-
if (is_writeable($destination . '/')) {
85-
$zip->extractTo($destination);
86-
$zip->close();
87-
$GLOBALS['status'] = array('success' => 'Dateien erfolgreich entpackt!');
88-
}
89-
else {
90-
$GLOBALS['status'] = array('error' => 'Fehler: Verzeichnis nicht vom Webserver schreibbar.');
88+
if ($zip->open($archive) === true) {
89+
// Check if destination is writable
90+
if (is_writeable($destination.'/')) {
91+
$zip->extractTo($destination);
92+
$zip->close();
93+
$_SESSION['status'] = array('success' => 'Dateien erfolgreich entpackt!');
94+
} else {
95+
$_SESSION['status'] = array('error' => 'Fehler: Verzeichnis nicht vom Webserver schreibbar.');
9196
}
92-
}
93-
else {
94-
$GLOBALS['status'] = array('error' => 'Fehler: Archiv nicht lesbar!');
97+
} else {
98+
$_SESSION['status'] = array('error' => 'Fehler: Archiv nicht lesbar!');
9599
}
96100
}
97101
/**
@@ -100,26 +104,27 @@ public static function extractZipArchive($archive, $destination) {
100104
* @param $archive
101105
* @param $destination
102106
*/
103-
public static function extractGzipFile($archive, $destination) {
104-
// Check if zlib is enabled
107+
public static function extractGzipFile($archive, $destination)
108+
{
109+
// Check if zlib is enabled
105110
if (!function_exists('gzopen')) {
106-
$GLOBALS['status'] = array('error' => 'Fehler: Your PHP has no zlib support enabled.');
107-
return;
108-
}
109-
$filename = pathinfo($archive, PATHINFO_FILENAME);
110-
$gzipped = gzopen($archive, "rb");
111-
$file = fopen($filename, "w");
112-
while ($string = gzread($gzipped, 4096)) {
113-
fwrite($file, $string, strlen($string));
111+
$_SESSION['status'] = array('error' => 'Fehler: Your PHP has no zlib support enabled.');
112+
113+
return;
114114
}
115-
gzclose($gzipped);
116-
fclose($file);
115+
$filename = pathinfo($archive, PATHINFO_FILENAME);
116+
$gzipped = gzopen($archive, 'rb');
117+
$file = fopen($filename, 'w');
118+
while ($string = gzread($gzipped, 4096)) {
119+
fwrite($file, $string, strlen($string));
120+
}
121+
gzclose($gzipped);
122+
fclose($file);
117123
// Check if file was extracted.
118-
if (file_exists($destination . '/' . $filename)) {
119-
$GLOBALS['status'] = array('success' => 'Datei erfolgreich entpackt.');
120-
}
121-
else {
122-
$GLOBALS['status'] = array('error' => 'Fehler beim entpacken der Datei.');
124+
if (file_exists($destination.'/'.$filename)) {
125+
$_SESSION['status'] = array('success' => 'Datei erfolgreich entpackt.');
126+
} else {
127+
$_SESSION['status'] = array('error' => 'Fehler beim entpacken der Datei.');
123128
}
124129
}
125130
/**
@@ -128,29 +133,29 @@ public static function extractGzipFile($archive, $destination) {
128133
* @param $archive
129134
* @param $destination
130135
*/
131-
public static function extractRarArchive($archive, $destination) {
132-
// Check if webserver supports unzipping.
136+
public static function extractRarArchive($archive, $destination)
137+
{
138+
// Check if webserver supports unzipping.
133139
if (!class_exists('RarArchive')) {
134-
$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>');
135-
return;
140+
$_SESSION['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>');
141+
142+
return;
136143
}
137144
// Check if archive is readable.
138145
if ($rar = RarArchive::open($archive)) {
139-
// Check if destination is writable
140-
if (is_writeable($destination . '/')) {
141-
$entries = $rar->getEntries();
142-
foreach ($entries as $entry) {
143-
$entry->extract($destination);
144-
}
145-
$rar->close();
146-
$GLOBALS['status'] = array('success' => 'Datei erfolreich entpackt.');
147-
}
148-
else {
149-
$GLOBALS['status'] = array('error' => 'Fehler: Verzeichnis nicht vom Webserver schreibbar.');
146+
// Check if destination is writable
147+
if (is_writeable($destination.'/')) {
148+
$entries = $rar->getEntries();
149+
foreach ($entries as $entry) {
150+
$entry->extract($destination);
151+
}
152+
$rar->close();
153+
$_SESSION['status'] = array('success' => 'Datei erfolreich entpackt.');
154+
} else {
155+
$_SESSION['status'] = array('error' => 'Fehler: Verzeichnis nicht vom Webserver schreibbar.');
150156
}
151-
}
152-
else {
153-
$GLOBALS['status'] = array('error' => 'Error: Archiv nicht lesbar!');
157+
} else {
158+
$_SESSION['status'] = array('error' => 'Error: Archiv nicht lesbar!');
154159
}
155160
}
156161
}

0 commit comments

Comments
 (0)