Hello Yuri,
unzip is perfect
zip not implemented.
what do you think ?
ps : concatPaths it's just a copy/past of fileManager
sorry for indentation..
unzip is perfect
zip not implemented.
what do you think ?
ps : concatPaths it's just a copy/past of fileManager
sorry for indentation..
PHP Code:
/**
* Concat paths.
* @param string | array $paths Ex. array('pathPart1', 'pathPart2', 'pathPart3')
* @return string
*/
protected function concatPaths($paths)
{
if (is_string($paths)) {
return Util::fixPath($paths);
}
$fullPath = '';
foreach ($paths as $path) {
$fullPath = Util::concatPath($fullPath, $path);
}
return $fullPath;
}
/**
* Zip path
*
* @param [type] $sourcePath php8 string|array
* @param string $fileName string
* @return ?string $content of zip
*/
public function zip($sourcePath, string $fileName) : ?string
{
if (!class_exists('\ZipArchive')) {
throw new Error("Class ZipArchive does not installed. Cannot zip the file.");
}
$path = $this->concatPaths($sourcePath);
if (!$path || !$fileName) {
return null;
}
$fileManager = $this->getFileManager();
$zip = new \ZipArchive;
$zip->open('data/tmp/' .$fileName, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
$fileList = $fileManager->getFileList($path);
foreach($fileList as $theFile) {
$zip->addFile($path .'/' .$theFile);
}
$zip->close();
$content = $fileManager->getContents('data/tmp/' .$file);
unlink('data/tmp/' .$file);
return $content;
}
Comment