PHP ZipArchive 不支持打开 UTF8 文件
PHP ZipArchive 不支持打开 UTF8 文件
PHP ZipArchive dont support UTF8 files for open
我的问题是使用 UTF8 名称打开文件.ZipArchive 不打开带有 UTF8 字符的文件.我不添加新文件,我只需要打开文件.
my problem is OPEN files with UTF8 name. ZipArchive dont open files with UTF8 character. i dont add new file i need only open file.
php: 5.6 并使用 Yii2.
php: 5.6 and Use Yii2.
代码:
$path = "files/تست تست.zip";
$zip = new ipArchive();
if($zip->open($path) === true) {
return "File opened";
}
else
{
return "File could not be opened";
}
推荐答案
很抱歉将其标记为不相关问题的重复项.
Sorry about marking this as a duplicate for an unrelated issue.
我可以使用 PHP 5.6 打开 UTF-8 zip 文件而不会出现问题.
I'm able to open UTF-8 zip files without a problem using PHP 5.6.
此代码将毫无问题地创建一个具有该文件名的新 ZIP 文件,其中包含一个test.txt"文件:
This code will create a new ZIP file with that filename without a problem, with a "test.txt" file in it:
$path = "تست تست.zip";
$zip = new ZipArchive();
if($zip->open($path, ZipArchive::CREATE) === true) {
echo "File opened
";
$zip->addFromString("test.txt", "Test file");
$zip->close();
} else {
echo "File could not be opened";
}
此代码将打开具有该名称的现有 ZIP 文件并打印出存档中的第一个文件名:
This code will open an existing ZIP file with that name and print out the first filename from within the archive:
$path = "تست تست.zip";
$zip2 = new ZipArchive();
if($zip2->open($path) === true) {
echo "File opened
";
echo $zip2->getNameIndex(0);
$zip2->close();
} else {
echo "File could not be opened";
}
这些示例在 PHP Sandbox 和 phptester.com(没有直接链接可用的).我也在 3v4l.org 上尝试过,但他们没有启用 php-zip 扩展,所以 ZipArchive
在那里不可用.
These examples work fine in the PHP Sandbox and on phptester.com (no direct link available). I tried it on 3v4l.org as well, but they don't have the php-zip extension enabled so ZipArchive
is not available there.
相关文章