初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\channel\wxapp;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use ZipArchive;
|
||||
/**
|
||||
* 小鹅通
|
||||
*/
|
||||
class Package extends Backend
|
||||
{
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 压缩
|
||||
* @remark 递归将文件夹中的所有文件和子文件夹添加到压缩包中
|
||||
* @param string $folderPath 文件夹路径
|
||||
* @param ZipArchive $zip 压缩包实例
|
||||
* @param string $parentFolder 父文件夹路径(用于保持相对路径)
|
||||
*/
|
||||
public function addFolderToZip($folderPath, $zip, $parentFolder = '') {
|
||||
$handle = opendir($folderPath);
|
||||
while (($file = readdir($handle)) !== false) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
$filePath = $folderPath . '/' . $file;
|
||||
|
||||
if (is_file($filePath)) {
|
||||
// 获取相对于父文件夹的路径
|
||||
$relativePath = ltrim($parentFolder . '/' . $file, '/');
|
||||
|
||||
// 将文件添加到压缩包中,并使用相对路径作为在压缩包中的文件名
|
||||
$zip->addFile($filePath, $relativePath);
|
||||
} elseif (is_dir($filePath)) {
|
||||
// 递归添加子文件夹中的文件和子文件夹
|
||||
$this->addFolderToZip($filePath, $zip, $parentFolder . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user