-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunzip.php
66 lines (52 loc) · 1.87 KB
/
unzip.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// Unzip for Symbiose WebOS
// Coded by TiBounise & $imon
// Released as GPL v3 software
if (!$this->arguments->isParam(0))
throw new InvalidArgumentException('Aucun fichier fourni');
$FileManager = $this->webos->managers()->get('File');
$AbsoluteLocation = $this->terminal->getAbsoluteLocation($this->arguments->getParam(0));
if (!$FileManager->exists($AbsoluteLocation))
throw new InvalidArgumentException('Le fichier n\'existe pas !');
$file = $FileManager->get($AbsoluteLocation);
// Check file type
if ($file->extension() != 'zip')
throw new InvalidArgumentException('Le fichier fourni ne semble pas être au format .zip');
// Generate the real paths
$FilePath = $file->realpath();
$ZipFilename = $file->basename();
$dest = $file->dirname();
if (!$FileManager->exists($dest)) {
$FolderPath = $FileManager->createDir($dest)->realpath();
} else {
$FolderPath = $FileManager->get($dest)->realpath();
}
// Stores the times at the beginning of the script
$startTime = time();
//Check available space
$zip = new ZipArchive;
$result = $zip->open($FilePath);
echo 'Archive: '.$file->basename()."\n";
// Unzip :P
if ($result === TRUE) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$entry = $zip->getNameIndex($i);
if (substr($entry, -1) == '/') { // Is this entry a directory ?
echo ' creating: '.$entry."\n";
$FileManager->createDir($dest.'/'.$entry);
} else {
echo ' extracting: '.$entry."\n";
$handle = $zip->getStream($entry);
$file = $FileManager->createFile($dest.'/'.$entry);
$contents = @stream_get_contents($handle);
if ($contents === false) {
echo 'Erreur : impossible d\'extraire « '.$entry.' ».'."\n";
}
$file->setContents($contents);
}
}
$zip->close();
echo $ZipFilename.' a été décompressé en '.(time() - $startTime).' secondes.';
} else {
throw new InvalidArgumentException('L\'archive n\'a pu etre extraite');
}