PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] PHP ZipArchive dont support UTF8 files for open

 March 08, 2022     php, php-zip-archive, utf-8, yii, yii2     No comments   

Issue

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

Solution

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.



Answered By - rickdenhaan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing