CaiWuXiTong/app/Jobs/Install/UnzipFile.php
15061959991 1adf627c0d feat: 财务系统二次开发 - 营销账户账单功能
- 基础环境:Docker 部署配置,源码挂载实时同步
- 修复:super_admin 权限补全、登录重定向循环
- 开发:店铺营销账户账单 - 抖音账户(15字段汇总账单)
- 开发:店铺营销账户账单 - 淘系支付宝账户(8字段流水账单)
- 开发:店铺营销账户账单 - 拼多多账户(7字段流水账单)
- 业务页面导航集成:config/business_navigation.php + Business\Pages 控制器
- 各平台独立表结构和视图,互不影响
2026-07-21 18:43:52 +08:00

80 lines
1.8 KiB
PHP

<?php
namespace App\Jobs\Install;
use App\Abstracts\Job;
use Illuminate\Support\Facades\File;
use ZipArchive;
class UnzipFile extends Job
{
protected $alias;
protected $path;
/**
* Create a new job instance.
*
* @param $alias
* @param $path
*/
public function __construct($alias, $path)
{
$this->alias = $alias;
$this->path = $path;
}
/**
* Execute the job.
*
* @return string
*/
public function handle()
{
if (empty($this->path)) {
throw new \Exception(trans('modules.errors.unzip', ['module' => $this->alias]));
}
$temp_path = storage_path('app/temp/' . $this->path);
$file = $temp_path . '/upload.zip';
// Unzip the file
$zip = new ZipArchive();
if (!$zip->open($file)) {
throw new \Exception(trans('modules.errors.unzip', ['module' => $this->alias]));
}
// Validate all entries before extraction to prevent ZipSlip path traversal attacks
for ($i = 0; $i < $zip->numFiles; $i++) {
$entry_name = $zip->getNameIndex($i);
if ($entry_name === false) {
continue;
}
if (
str_contains($entry_name, '..') ||
str_starts_with($entry_name, '/') ||
str_starts_with($entry_name, '\\') ||
str_contains($entry_name, "\0")
) {
$zip->close();
throw new \Exception(trans('modules.errors.unzip', ['module' => $this->alias]));
}
}
if (!$zip->extractTo($temp_path)) {
throw new \Exception(trans('modules.errors.unzip', ['module' => $this->alias]));
}
$zip->close();
// Remove Zip
File::delete($file);
return $this->path;
}
}