PHP ZipArchive不支持UTF8文件打开 [英] PHP ZipArchive dont support UTF8 files for open

查看:225
本文介绍了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 \ZipArchive();
        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\n";
    $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\n";
    echo $zip2->getNameIndex(0);
    $zip2->close();
} else {
    echo "File could not be opened";
}

这些示例在 PHP沙箱和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.

这篇关于PHP ZipArchive不支持UTF8文件打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆