diff --git a/README.md b/README.md index 968cbaa..6cbdc62 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ As of version 0.1.0 it also supports creating archives. It's handy if you do not have shell access. E.g. if you want to upload a lot of files (php framework or image collection) as archive - because it is much faster than uploading each file by itself. -## Requirements +## Requirements PHP 5.3 and newer (If you still run PHP < 5.6 you should consider updating PHP. These old PHP versions do not get any security updates and your site may be vulnerable.) @@ -24,6 +24,11 @@ PHP 5.3 and newer * (Optional) Set path to zip, defaults to current directory * Click "Zip Archive" +### Multipart zipper +* Choose .001 files that you want to zip. +* Files will only display if the uploaded split files is created in 7zip +* Click "Multipart Zip" + ## Version Beta version state, use at you own risk. @@ -32,13 +37,13 @@ Beta version state, use at you own risk. Released under GNU/GPL v3 -## Screenshot +## Screenshot  -## Updates +## Updates Get latest code at https://github.com/ndeet/unzipper -## Credits -[See contributors on Github](https://github.com/ndeet/unzipper/graphs/contributors) +## Credits +[See contributors on Github](https://github.com/ndeet/unzipper/graphs/contributors) diff --git a/unzipper.php b/unzipper.php index b7b1bbc..c4ba87d 100644 --- a/unzipper.php +++ b/unzipper.php @@ -1,4 +1,5 @@ localdir)) { while (($file = readdir($dh)) !== FALSE) { - if (pathinfo($file, PATHINFO_EXTENSION) === 'zip' + if ( + pathinfo($file, PATHINFO_EXTENSION) === 'zip' || pathinfo($file, PATHINFO_EXTENSION) === 'gz' || pathinfo($file, PATHINFO_EXTENSION) === 'rar' + || pathinfo($file, PATHINFO_EXTENSION) === '001' ) { $this->zipfiles[] = $file; } @@ -55,11 +71,12 @@ public function __construct() { if (!empty($this->zipfiles)) { $GLOBALS['status'] = array('info' => '.zip or .gz or .rar files found, ready for extraction'); - } - else { + } else { $GLOBALS['status'] = array('info' => 'No .zip or .gz or rar files found. So only zipping functionality available.'); } } + + } /** @@ -70,12 +87,12 @@ public function __construct() { * @param string $destination * The relative destination path where to extract files. */ - public function prepareExtraction($archive, $destination = '') { + public function prepareExtraction($archive, $destination = '') + { // Determine paths. if (empty($destination)) { $extpath = $this->localdir; - } - else { + } else { $extpath = $this->localdir . '/' . $destination; // Todo: move this to extraction function. if (!is_dir($extpath)) { @@ -96,7 +113,8 @@ public function prepareExtraction($archive, $destination = '') { * @param string $destination * The relative destination path where to extract files. */ - public static function extract($archive, $destination) { + public static function extract($archive, $destination) + { $ext = pathinfo($archive, PATHINFO_EXTENSION); switch ($ext) { case 'zip': @@ -109,7 +127,6 @@ public static function extract($archive, $destination) { self::extractRarArchive($archive, $destination); break; } - } /** @@ -118,7 +135,8 @@ public static function extract($archive, $destination) { * @param $archive * @param $destination */ - public static function extractZipArchive($archive, $destination) { + public static function extractZipArchive($archive, $destination) + { // Check if webserver supports unzipping. if (!class_exists('ZipArchive')) { $GLOBALS['status'] = array('error' => 'Error: Your PHP version does not support unzip functionality.'); @@ -134,12 +152,10 @@ public static function extractZipArchive($archive, $destination) { $zip->extractTo($destination); $zip->close(); $GLOBALS['status'] = array('success' => 'Files unzipped successfully'); - } - else { + } else { $GLOBALS['status'] = array('error' => 'Error: Directory not writeable by webserver.'); } - } - else { + } else { $GLOBALS['status'] = array('error' => 'Error: Cannot read .zip archive.'); } } @@ -152,7 +168,8 @@ public static function extractZipArchive($archive, $destination) { * @param string $destination * The relative destination path where to extract files. */ - public static function extractGzipFile($archive, $destination) { + public static function extractGzipFile($archive, $destination) + { // Check if zlib is enabled if (!function_exists('gzopen')) { $GLOBALS['status'] = array('error' => 'Error: Your PHP has no zlib support enabled.'); @@ -182,11 +199,9 @@ public static function extractGzipFile($archive, $destination) { unlink($destination . '/' . $filename); } } - } - else { + } else { $GLOBALS['status'] = array('error' => 'Error unzipping file.'); } - } /** @@ -197,7 +212,8 @@ public static function extractGzipFile($archive, $destination) { * @param string $destination * The relative destination path where to extract files. */ - public static function extractRarArchive($archive, $destination) { + public static function extractRarArchive($archive, $destination) + { // Check if webserver supports unzipping. if (!class_exists('RarArchive')) { $GLOBALS['status'] = array('error' => 'Error: Your PHP version does not support .rar archive functionality. How to install RarArchive'); @@ -213,16 +229,13 @@ public static function extractRarArchive($archive, $destination) { } $rar->close(); $GLOBALS['status'] = array('success' => 'Files extracted successfully.'); - } - else { + } else { $GLOBALS['status'] = array('error' => 'Error: Directory not writeable by webserver.'); } - } - else { + } else { $GLOBALS['status'] = array('error' => 'Error: Cannot read .rar archive.'); } } - } /** @@ -231,7 +244,8 @@ public static function extractRarArchive($archive, $destination) { * Copied and slightly modified from http://at2.php.net/manual/en/class.ziparchive.php#110719 * @author umbalaconmeogia */ -class Zipper { +class Zipper +{ /** * Add files and sub-directories in a folder to zip file. * @@ -244,7 +258,8 @@ class Zipper { * @param int $exclusiveLength * Number of text to be exclusived from the file path. */ - private static function folderToZip($folder, &$zipFile, $exclusiveLength) { + private static function folderToZip($folder, &$zipFile, $exclusiveLength) + { $handle = opendir($folder); while (FALSE !== $f = readdir($handle)) { @@ -256,8 +271,7 @@ private static function folderToZip($folder, &$zipFile, $exclusiveLength) { if (is_file($filePath)) { $zipFile->addFile($filePath, $localPath); - } - elseif (is_dir($filePath)) { + } elseif (is_dir($filePath)) { // Add sub-directory. $zipFile->addEmptyDir($localPath); self::folderToZip($filePath, $zipFile, $exclusiveLength); @@ -279,7 +293,8 @@ private static function folderToZip($folder, &$zipFile, $exclusiveLength) { * @param string $outZipPath * Relative path of the resulting output zip file. */ - public static function zipDir($sourcePath, $outZipPath) { + public static function zipDir($sourcePath, $outZipPath) + { $pathInfo = pathinfo($sourcePath); $parentPath = $pathInfo['dirname']; $dirName = $pathInfo['basename']; @@ -289,24 +304,60 @@ public static function zipDir($sourcePath, $outZipPath) { $z->addEmptyDir($dirName); if ($sourcePath == $dirName) { self::folderToZip($sourcePath, $z, 0); - } - else { + } else { self::folderToZip($sourcePath, $z, strlen("$parentPath/")); } $z->close(); $GLOBALS['status'] = array('success' => 'Successfully created archive ' . $outZipPath); } + + + public static function multipartZipped($splitfile, $zipfile) + { + $localdir = '.'; + + if(!$splitfile) { + $GLOBALS['status'] = array('error' => 'No split files exists.'); + return; + } + + if ($dh = opendir($localdir)) { + // Removed the 1 in the first split file + $splitfileRemoveOne = str_replace('1', '', $splitfile); + + // Remove the existing zip file + if(file_exists($zipfile)) { + $GLOBALS['status'] = array('error' => 'File already exists old file will be overwritten.'); + unlink($zipfile); + } else { + $GLOBALS['status'] = array('success' => 'Multipart files merged. Extract it using Archive Unzipper below'); + } + // Join multipart files + while (($file = readdir($dh)) !== FALSE) { + // Check for split files that contains .zip.00 + if (str_contains($file, $splitfileRemoveOne) && + file_exists($file) + ) { + // Get the content of the file + $content = file_get_contents($file); + // Combine multipart files into one + file_put_contents($zipfile, $content, FILE_APPEND); + } + } + closedir($dh); + } + } } ?> +
- Status:
- Processing Time: seconds
-
Unzipper version:
+
+ Status:
+ Processing Time: seconds
+
Unzipper version:
+