简体   繁体   English

在zip php中写入unicode文件名(Linux服务器)

[英]Write unicode file name in zip php (linux server)

I use ZipArchive to zip all photos. 我使用ZipArchive压缩所有照片。 The filename of original photo has character unicode. 原始照片的文件名具有字符unicode。 After all photos are compressed to a zip file, the filename of photo is changed to the other character. 将所有照片压缩为zip文件后,照片的文件名将更改为其他字符。

For example original filename of photo is "កែវ កេត_1429672475273.jpg" , it will be "сЮАсЯВсЮЬ сЮАсЯБсЮП_1429672475273.jpg" in zip file. 例如,照片的原始文件名是"កែវ កេត_1429672475273.jpg" ,在压缩文件中将是"сЮАсЯВсЮЬ сЮАсЯБсЮП_1429672475273.jpg"

This is my simple code : 这是我的简单代码:

$zip = new ZipArchive();
$filename = 'photos.zip';
if ($zip->open($filename, ZipArchive::OVERWRITE) !== TRUE) {
    exit("Cannot open <$filename>");
}
$teachers = array(
    'កែវ កេត_1429672475273.jpg',
    'ផាន់ ចាន់រស្មី_1429671047820.jpg',
    'ម៉ៅ ហៀង_1427422340782.jpg',
);
foreach ($teachers as $teacherFileName) {
    if (file_exists($teacherFileName) && is_file($teacherFileName)) {
        $zip->addFile($teacherFileName, 'teachers/' . $teacherFileName);
    }
}

$zip->addFromString('version.txt', date('YmdHis'));
$zip->close();

These are files with unicodes : 这些是带有unicode的文件:

在此处输入图片说明

The file name is not the same characters unicode of original file: 文件名不是原始文件的相同字符unicode:

在此处输入图片说明

My current server is Ubuntu 14.10 64bit (local machine) and Gentoo 64bit (real server). 我当前的服务器是Ubuntu 14.10 64位(本地计算机)和Gentoo 64位(真实服务器)。 And the results are the same. 结果是一样的。

Thanks in advance! 提前致谢!

I couldn't find any question in your text but still will try to help why its so. 我在您的文字中找不到任何问题,但仍会尝试帮助其解释。

The zip format stores filenames as sequence of bytes. zip格式将文件名存储为字节序列。

it's up to the zip handling tool how to interpret the names, ie in your case nautilus . 由zip处理工具决定如何解释名称,即在您的情况下是nautilus

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM