feat: init project codebase
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* 压缩整个目录
|
||||
*/
|
||||
class MakeZip
|
||||
{
|
||||
|
||||
/**
|
||||
* description:主方法:生成压缩包
|
||||
* @author: MY
|
||||
* @param $dir_path 想要压缩的目录:如 './demo/'
|
||||
* @param $zipName 压缩后的文件名:如 './folder/demo.zip'
|
||||
* @return string
|
||||
*/
|
||||
function zip($dir_path, $zipName)
|
||||
{
|
||||
// Get real path for our folder
|
||||
$rootPath = realpath($dir_path);
|
||||
|
||||
// Initialize archive object
|
||||
$zip = new ZipArchive();
|
||||
$zip->open($zipName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||||
|
||||
// Create recursive directory iterator
|
||||
/** @var SplFileInfo[] $files */
|
||||
$files = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($rootPath),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY
|
||||
);
|
||||
|
||||
foreach ($files as $name => $file)
|
||||
{
|
||||
// Skip directories (they would be added automatically)
|
||||
if (!$file->isDir())
|
||||
{
|
||||
// Get real and relative path for current file
|
||||
$filePath = $file->getRealPath();
|
||||
$relativePath = substr($filePath, strlen($rootPath) + 1);
|
||||
|
||||
// Add current file to archive
|
||||
$zip->addFile($filePath, $relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
// Zip archive will be created only after closing object
|
||||
$zip->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user