Hongmu Notes
Home Summary of pitfalls PHP-based archive extraction/compression tool; the archive contains a file with a Chinese name – why does an error occur after extraction?
Summary of pitfalls

PHP-based archive extraction/compression tool; the archive contains a file with a Chinese name – why does an error occur after extraction?

PHP-based archive extraction/compression tool; the archive contains a file with a Chinese name – why does an error occur after extraction?

If the file name within a compressed archive contains Chinese characters, the archive may contain corrupted text or fail to decompress after extraction. This occurs when the encoding used for the file name in the archive does not match the encoding supported by the decompression program.

Typically, the filenames within a compressed archive are encoded using the operating system's default encoding method, whereas the decompression program may employ a different encoding method. When a filename contains non-ASCII characters (e.g., Chinese characters), encoding inconsistencies may occur.

To avoid this issue, you can use PHP's ZipArchive class to decompress files and set the file name encoding to UTF-8 before decompression. Here is an example code:

$zip = new ZipArchive;
$res = $zip->open('/path/to/zipfile.zip');
if ($res === TRUE) {
  $zip->setOptions(array('default_charset' => 'UTF-8')); // 设置文件名编码方式为 UTF-8
  $zip->extractTo('/path/to/extract'); // 解压缩到指定目录
  $zip->close();
  echo '解压缩完成';
} else {
  echo '解压缩失败';
}

In this example,$zip It is. ZipArchive An instance used to open and decompress a compressed archive. Call this method. $zip->extractTo() Before use, please follow the instructions. $zip->setOptions() Set the file name encoding method to UTF-8 so that file names containing Chinese characters can be processed correctly. Finally, call the function. $zip->close() Close the compressed archive.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Browser caching increases the speed of secondary visits to your website

Browser caching increases the speed of secondary visits to your website Summary of pitfalls

Use browser caching of official words: If users will visit your website multiple times, browser caching of static resources can save users time. Cache headers should be applied to all cacheable static resources, not just to a small subset of static resources (for example, images). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDF files, etc.). Normally, HTML doesn’t…
👁 202

Recommended reading

(PC+WAP)陶粒批发企业网站 – pbootCMS template; Engineering and Construction Materials Website Source Code Download – 0127

(PC+WAP)陶粒批发企业网站 – pbootCMS template; Engineering and Construction Materials Website Source Code Download – 0127 Practical Collection pbootcms Template

This PbootCMS template is designed for the expanded clay aggregate wholesale and construction materials industries, supporting both PC and mobile devices. Its pragmatic and professional design effectively showcases the applications of expanded clay aggregate products in the construction sector. It enables building material suppliers to display product specifications and project cases online, helping them expand their customer base within the construction industry. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4...
👁 51
Responsive Rosewood Solid Wood Furniture Website Template 0923

Responsive Rosewood Solid Wood Furniture Website Template 0923 Practical Collection Yiyou template

An eYouCMS responsive website template designed for the rosewood and solid wood furniture industry. Its classical, high-end design style is ideal for showcasing rosewood furniture products, solid wood collections, brand stories, and customisation services. This template helps rosewood furniture brands showcase their products online and attract high-end customers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS...
👁 54
(Adaptive mobile version) Government agency website template; Download organizational association website source code – 1091

(Adaptive mobile version) Government agency website template; Download organizational association website source code – 1091 Practical Collection pbootcms Template

A PbootCMS website template designed for government agencies and organizational associations, compatible with both PC and WAP devices. Its sophisticated and professional design makes it ideal for government bodies and social organizations to showcase their functions, policies, and services. This template helps public institutions establish an official online information dissemination platform. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 43
(PC + WAP) Catering & Milk Tea Franchise Website – pbootCMS Template; Food & Snack Franchise Website Source Code Download – 0128

(PC + WAP) Catering & Milk Tea Franchise Website – pbootCMS Template; Food & Snack Franchise Website Source Code Download – 0128 Practical Collection pbootcms Template

A PbootCMS website template designed for the catering, milk tea franchise and food & snack industries, supporting both PC and WAP devices. Its fashionable and vibrant design effectively appeals to young entrepreneurs. The template includes built-in modules for brand storytelling, franchise policies, and online consultation – making it a powerful tool for fast-track franchise recruitment for restaurant chains. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extract...
👁 67
Building Materials – Stone板材 Website Template 0924

Building Materials – Stone板材 Website Template 0924 Practical Collection Yiyou template

This EyouCMS template is ideal for the building materials, stone, and panel industries. Its professional design style is perfect for showcasing stone products, panel series, building materials, and project cases. It helps building material companies present their products online and attract construction developers and renovation firms. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS...
👁 48
(Adaptive mobile version) Bilingual (Chinese/English) website template; Electronic components & semiconductor chip website template – 1092

(Adaptive mobile version) Bilingual (Chinese/English) website template; Electronic components & semiconductor chip website template – 1092 Practical Collection pbootcms Template

A bilingual (Chinese/English) PbootCMS website template designed for electronic component and chip R&D enterprises, supporting both PC and WAP devices. Its modern, international design is ideal for showcasing products and technologies. The multilingual support facilitates effective brand promotion in global markets. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.c...
👁 44