作者 李小龙

a

... ... @@ -141,33 +141,6 @@ public function uploadAmpVerifyFile(Request $request): string
return $this->success();
}
/**
* 压缩文件夹
*/
public function createZipFile(){
$folderPath = public_path("target");
$zipFilePath = public_path().'/target.zip';
$zip = new ZipArchive();
if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
// 递归添加文件夹下的所有文件和子文件夹
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($folderPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($folderPath) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
echo '文件夹压缩成功';
} else {
echo '无法打开或创建压缩文件';
}
}
/**
* 获取需要下载的文件url
... ... @@ -181,6 +154,8 @@ public function websiteHtml(Request $request){
$token = env("WEB_SITE_TOKEN");
$apiUrl = env("API_URL");
$requestUrl = $apiUrl."?domain=".$domain."&token=".$token;
@file_put_contents(storage_path('logs/notify_get_url.log'), date('Y-m-d H:i:s') . "接收到通知:". $requestUrl . PHP_EOL, FILE_APPEND);
try {
$res = $this->curlGet($requestUrl);
... ... @@ -192,44 +167,44 @@ public function websiteHtml(Request $request){
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
return $this->websiteHtmlHandle($url);
return $this->websiteHtmlHandle($url,$domain);
}
/**
* 网站html解压
* @param $url
* @return string
*/
public function websiteHtmlHandle($url)
{
$pathInfo = pathinfo($url);
$extension = $pathInfo['extension'];
//只允许解压zip格式文件
if (in_array($extension, ["zip"])) {
try {
$targetFile = $this->downLoadFile($url);
$zip = new ZipArchive();
if ($zip->open($targetFile) === TRUE) {
$outputFolder = public_path();
if (!is_dir($outputFolder)) {
mkdir($outputFolder, 0777, true);
}
// 解压缩文件,保留原文件结构
$zip->extractTo($outputFolder);
$zip->close();
$this->deleteDirectory($targetFile);
} else {
return $this->error('解压失败!');
// 处理打开压缩文件失败的情况
/**
* 网站html解压
* @param $url
* @return string
*/
public function websiteHtmlHandle($url,$domain)
{
$pathInfo = pathinfo($url);
$extension = $pathInfo['extension'];
//只允许解压zip格式文件
if (in_array($extension, ["zip"])) {
try {
$targetFile = $this->downLoadFile($url);
$zip = new ZipArchive();
if ($zip->open($targetFile) === TRUE) {
$outputFolder = public_path($domain);
if (!is_dir($outputFolder)) {
mkdir($outputFolder, 0777, true);
}
} catch (\Exception $e) {
return $this->error($e->getMessage());
// 解压缩文件,保留原文件结构
$zip->extractTo($outputFolder);
$zip->close();
$this->deleteDirectory($targetFile);
} else {
return $this->error('解压失败!');
// 处理打开压缩文件失败的情况
}
}else{
return $this->error('不允许解压改格式压缩包!');
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
return $this->success();
}else{
return $this->error('不允许解压改格式压缩包!');
}
return $this->success();
}
/**
* 下载文件(下载到public目录下)
... ...