ZipArchive::ER_CRC
php
data_error
ai_generated
partial
ZipArchive::extractTo():无法解压 zip 存档 '/tmp/upload_abc123.zip':ZipArchive::ER_CRC 错误,位于 /var/www/app/src/Import/ZipImporter.php 第 42 行
ZipArchive::extractTo(): Failed to extract zip archive '/tmp/upload_abc123.zip': ZipArchive::ER_CRC error in /var/www/app/src/Import/ZipImporter.php on line 42
ID: php/zip-archive-corrupt-archive
70%修复率
87%置信度
1证据数
2025-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.4 | active | — | — | — |
| 8.0 | active | — | — | — |
| 8.1 | active | — | — | — |
| 8.2 | active | — | — | — |
| 8.3 | active | — | — | — |
根因分析
ZIP 存档损坏或不完整,通常由上传失败、下载中断或磁盘写入错误引起,导致解压时 CRC 校验和不匹配。
English
The ZIP archive is corrupt or incomplete, often due to a failed upload, truncated download, or disk write error, causing CRC checksum mismatches during extraction.
官方文档
https://www.php.net/manual/en/ziparchive.extractto.php解决方案
-
Validate the ZIP file integrity before extraction using ZipArchive::open() with ZipArchive::CHECKCONS: $zip = new ZipArchive(); if ($zip->open($file, ZipArchive::CHECKCONS) !== true) { throw new Exception('Corrupt archive'); } -
Re-download or re-upload the ZIP file from the source, ensuring a complete transfer. Use checksums (e.g., MD5) to verify integrity.
-
Use a command-line tool like 'unzip -t archive.zip' to test the archive, then repair with 'zip -F archive.zip --out fixed.zip' if possible.
无效尝试
常见但无效的做法:
-
95% 失败
CRC errors are data integrity issues, not resource limits. Increasing limits won't fix corrupted data.
-
80% 失败
If the source file is corrupt on disk, re-uploading the same file yields the same CRC error.