PHP ZipArchive dont support UTF8 files for open

流过昼夜 提交于 2019-12-02 10:48:10

问题


PHP ZipArchive dont support UTF8 files for open

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 and Use Yii2.

code:

$path = "files/تست تست.zip";
        $zip = new \ZipArchive();
        if($zip->open($path) === true) {

            return "File opened";
        }
        else
        {
            return "File could not be opened";
        }

回答1:


Sorry about marking this as a duplicate for an unrelated issue.

I'm able to open UTF-8 zip files without a problem using PHP 5.6.

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";
}

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";
}

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.



来源:https://stackoverflow.com/questions/45154025/php-ziparchive-dont-support-utf8-files-for-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!