Home  >  Article  >  Backend Development  >  Solve the problem of Chinese garbled characters in PclZip

Solve the problem of Chinese garbled characters in PclZip

WBOY
WBOYOriginal
2016-08-08 09:28:241271browse

When using Pclzip, the file cannot be compressed/decompressed. After tracking the error message, I found that the file/directory cannot be opened, but the folder permissions are correct. After printing the file path, I found that it was garbled. The reason for this problem is that the file name encoding in the zip under Windows is gb2312, while PHP uses utf-8 encoding. The solution is to modify the pclzip.php class file:

Modify the compressed file part:

privAddFile method:

//$p_header['stored_filename'] = $p_filedescr['stored_filename'];

// Modify to the following line

$p_header['stored_filename'] = mb_convert_encoding( $p_filedescr['stored_filename'],'GB2312','UTF-8');

Modify the decompressed file part:

privExtractFile method:

$p_entry['filename'] = $p_path."/".$p_entry['filename'];

// Add the following line

$p_entry['filename' ] = mb_convert_encoding($p_entry['filename'], 'UTF-8', 'gb2312');

The above has introduced how to solve the problem of Chinese garbled characters in PclZip, including aspects of the problem. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Ajax request json dataNext article:Ajax request json data