feat: init project codebase

This commit is contained in:
sinde21
2026-09-14 16:32:07 +08:00
parent c4b2a15757
commit da20fde7fb
140 changed files with 27855 additions and 0 deletions
+51
View File
@@ -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;
}
}