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); $savename = \think\facade\Filesystem::putFile('zippic', $file);
$dir = date('Y-m-d_H-i-s') . '_' . $mer_id; $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 { try {
$zip = new ZipArchive; $zipFile
$filePath = public_path('uploads') . $savename; ->openFile(public_path('uploads').$savename) // open archive from file
$zip->open($filePath); ->extractTo($destination_path) // add an entry from the string
for ($i = 0; $i < $zip->numFiles; $i++) { // ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files
$statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW); ->close(); // close archive
$filename = $this->transcoding($statInfo['name']); } catch (\PhpZip\Exception\ZipException $e) {
$mkdFile = explode('/',$filename); throw new \think\exception\HttpException(404,$e->getMessage());
if ($statInfo['crc'] == 0) { } finally {
// 新建目录 $zipFile->close();
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);
} // if ($zip->open(public_path('uploads').$savename) === TRUE) {
} // $zip->extractTo($destination_path);
} // $zip->close();
$zip->close(); // } else {
} catch (\Exception $e) { // throw new \think\exception\HttpException(404, '解压失败');
throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine()); // }
}
$directory = $destination_path; $directory = $destination_path;
$files = scandir($directory); $files = scandir($directory);
$dir = 'def/' . date('Y-m-d'); $dir = 'def/' . date('Y-m-d');