Jump to content

ZipArchive () problem with special characters in filenames


gdfhghjdfghgfhf

Recommended Posts

I use ZipArchive(); to list the file names inside a Zip archive (uploaded on FTP by different users, not created by server).

Problem is that some of the file names contain french caracters (accents like é à ô â à è) that are not displayed proprely. Instead i get a "�" symbol.

The page is encoded in utf8 and the rest of the script doesnt have any problem with accents

i tried running htmlentities() or utf8_encode() on $toune but it didnt help...

 

here's my code:

 

header('Content-Type: text/html; charset=utf-8');
$downloadlink = "pp/86 Crew - 2000 - Bad Bad Reggae.zip";
$za = new ZipArchive();
$za->open($downloadlink);
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$tounes = array( basename( $stat['name'] ) . PHP_EOL );
foreach($tounes as $toune) {
echo $toune;
}
}

 

 

 

Link to comment
Share on other sites

This is an interesting question. Apparently, from a quick google, there may not be a clear solution since the codepage of the character set used isn't stored in the zip file, unless the sources I referenced are incorrect.

 

One obvious issue to start with is that the base name() function is "locale aware" so you would want to setlocale appropriately. I would suggest starting with that issue.

Link to comment
Share on other sites

If you're running it only to show the contents of the zip file, why not make a temporary copy of the zip file with a different file name, you know, with normal alpha-numeric characters, and use that in ZipArchive() and auto-delete it once the contents are shown?

Link to comment
Share on other sites

If you're running it only to show the contents of the zip file, why not make a temporary copy of the zip file with a different file name, you know, with normal alpha-numeric characters, and use that in ZipArchive() and auto-delete it once the contents are shown?

 

problem is with the filenames inside the archive, not the filename of the archive.

Link to comment
Share on other sites

  • 5 weeks later...

Wow....I saw your urgent post onto the php freelancing section.

That one could be very simple with 2-3 lines of code, no more.

Just run a unzip linux command through bash with shell_exec in php and display the results on the page.

That's all.

 

PS: what happened here?  -> http://forums.phpfreaks.com/topic/280579-regexiterator-recursive-iterator-cant-search-file-with-accents/

Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.