This commit is contained in:
mkm 2023-11-30 09:15:35 +08:00
parent 7cbee24d8d
commit cbadbca096

View File

@ -36,36 +36,27 @@ class Demo extends BaseController
// 上传到本地服务器
$savename = \think\facade\Filesystem::putFile('zippic', $file);
$dir = date('Y-m-d_H-i-s') . '_' . $mer_id;
$path = public_path('uploads/pic').$dir;
$destination_path = public_path('uploads/pic/' . $dir.'_'.$zip_name);
mkdir($destination_path, 0777, true);
$zipFile = new \PhpZip\ZipFile();
try {
$zip = new ZipArchive;
$filePath = public_path('uploads') . $savename;
$zip->open($filePath);
for ($i = 0; $i < $zip->numFiles; $i++) {
$statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW);
$filename = $this->transcoding($statInfo['name']);
$mkdFile = explode('/',$filename);
if ($statInfo['crc'] == 0) {
// 新建目录
if (!file_exists($path . '/' . $filename)) {
mkdir($path . '/' . $filename, 0777, true);
}
// $this->createDirectories($path . '/' . $filename);
} else {
// 拷贝文件
if(count($mkdFile)==3){
if (!file_exists($path . '/' . $mkdFile[0].'/'.$mkdFile[1])) {
mkdir($path . '/' .$mkdFile[0].'/'.$mkdFile[1], 0777, true);
}
copy('zip://' . $file . '#' . $zip->getNameIndex($i), $path . '/' . $filename);
}
}
}
$zip->close();
} catch (\Exception $e) {
throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine());
$zipFile
->openFile(public_path('uploads').$savename) // open archive from file
->extractTo($destination_path) // add an entry from the string
// ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files
->close(); // close archive
} catch (\PhpZip\Exception\ZipException $e) {
throw new \think\exception\HttpException(404,$e->getMessage());
} finally {
$zipFile->close();
}
// if ($zip->open(public_path('uploads').$savename) === TRUE) {
// $zip->extractTo($destination_path);
// $zip->close();
// } else {
// throw new \think\exception\HttpException(404, '解压失败');
// }
$directory = $destination_path;
$files = scandir($directory);
$dir = 'def/' . date('Y-m-d');