Jump to content

ZipArchive () problem with special characters in filenames


Guest

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:

 

Quote
header('Content-Type: text/html; charset=utf-8');
$downloadlink = "pp/[redacted].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;
}
}

 

 

 

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.

 

 

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.

Sorry i'm not sure what you mean :/ ... still a beginner with the advanced php stuff

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?

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.

  • 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/

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.