正在显示
1 个修改的文件
包含
32 行增加
和
2 行删除
| @@ -12,6 +12,8 @@ | @@ -12,6 +12,8 @@ | ||
| 12 | use Illuminate\Http\JsonResponse; | 12 | use Illuminate\Http\JsonResponse; | 
| 13 | use Illuminate\Http\Request; | 13 | use Illuminate\Http\Request; | 
| 14 | use Illuminate\Support\Facades\Log; | 14 | use Illuminate\Support\Facades\Log; | 
| 15 | +use RecursiveDirectoryIterator; | ||
| 16 | +use RecursiveIteratorIterator; | ||
| 15 | use ZipArchive; | 17 | use ZipArchive; | 
| 16 | 18 | ||
| 17 | /** | 19 | /** | 
| @@ -140,14 +142,42 @@ public function uploadAmpVerifyFile(Request $request): string | @@ -140,14 +142,42 @@ public function uploadAmpVerifyFile(Request $request): string | ||
| 140 | } | 142 | } | 
| 141 | 143 | ||
| 142 | /** | 144 | /** | 
| 145 | + * 压缩文件夹 | ||
| 146 | + */ | ||
| 147 | + public function createZipFile(){ | ||
| 148 | + $folderPath = public_path("target"); | ||
| 149 | + $zipFilePath = public_path().'/target.zip'; | ||
| 150 | + $zip = new ZipArchive(); | ||
| 151 | + if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { | ||
| 152 | + // 递归添加文件夹下的所有文件和子文件夹 | ||
| 153 | + $files = new RecursiveIteratorIterator( | ||
| 154 | + new RecursiveDirectoryIterator($folderPath), | ||
| 155 | + RecursiveIteratorIterator::LEAVES_ONLY | ||
| 156 | + ); | ||
| 157 | + foreach ($files as $name => $file) { | ||
| 158 | + if (!$file->isDir()) { | ||
| 159 | + $filePath = $file->getRealPath(); | ||
| 160 | + $relativePath = substr($filePath, strlen($folderPath) + 1); | ||
| 161 | + $zip->addFile($filePath, $relativePath); | ||
| 162 | + } | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + $zip->close(); | ||
| 166 | + echo '文件夹压缩成功'; | ||
| 167 | + } else { | ||
| 168 | + echo '无法打开或创建压缩文件'; | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + /** | ||
| 143 | * 获取需要下载的文件url | 173 | * 获取需要下载的文件url | 
| 144 | * @param Request $request | 174 | * @param Request $request | 
| 145 | * @return string | 175 | * @return string | 
| 146 | */ | 176 | */ | 
| 147 | public function websiteHtml(Request $request){ | 177 | public function websiteHtml(Request $request){ | 
| 148 | -// $domain = $request->getHost(); | 178 | + $domain = $request->getHost(); | 
| 149 | //临时测试域名 | 179 | //临时测试域名 | 
| 150 | - $domain = "v6-1x28w.globalso.site"; | 180 | +// $domain = "v6-1x28w.globalso.site"; | 
| 151 | $token = env("WEB_SITE_TOKEN"); | 181 | $token = env("WEB_SITE_TOKEN"); | 
| 152 | $apiUrl = env("API_URL"); | 182 | $apiUrl = env("API_URL"); | 
| 153 | $requestUrl = $apiUrl."?domain=".$domain."&token=".$token; | 183 | $requestUrl = $apiUrl."?domain=".$domain."&token=".$token; | 
- 
请 注册 或 登录 后发表评论