unicode - Error While Renaming An Extracted Zip File To Other Languages In PHP -
i use php ziparchive class extract .zip file, works fine english, cause problems in local language (thai).
i use icov('utf-8','windows-874',$zip->getnameindex($i))
convert utf-8 thai. works folder's/file's name, doesn't work extracted .zip file , cause error :
iconv(): detected illegal character in input string
can please tell me problem here?
my php code
$file = iconv('utf-8', 'windows-874', $_get['file']); $path = iconv('utf-8', 'windows-874', $_get['path']); $zip = new ziparchive; if ($zip->open($file) === true) { // convert thai language for($i = 0; $i < $zip->numfiles; $i++) { $name = $zip->getnameindex($i); //echo iconv("charset zip file", "windows-874", $name); //$zip->extractto($path,$name); -> problem } $zip->close(); echo json_encode('unzip!!!'); } else { echo json_encode('failed'); }
after extract zipped file, file's name not 1 set it.
this name try set :
here zipped file :
https://www.dropbox.com/s/9f4j04lkvsyuy63/test.zip?dl=0
update
tried unzipping file in windows xp, works fine there not in windows 7.
you should try mb_detect_encoding() - see code below. may need expand on code if have problem path. use loop if need that.
$file = iconv('utf-8', 'windows-874', $_get['file']); $path = iconv('utf-8', 'windows-874', $_get['path']); $zip = new ziparchive; if ($zip->open($file) === true) { // convert thai language for($i = 0; $i < $zip->numfiles; $i++) { $name = $zip->getnameindex($i); $order = mb_detect_order(); $encoding = mb_detect_encoding($name, $order, true); if (false === $encoding) { throw new unexpectedvalueexception( sprintf( 'unable detect input encoding mb_detect_encoding, order was: %s' , print_r($order, true) ) ); } else { $encoding = mb_detect_encoding($name); $stringutf8 = iconv($encoding, 'utf-8//ignore', $name); $zip->extractto($path,$stringutf8); } } $zip->close(); echo json_encode('unzip!!!'); } else { echo json_encode('failed'); }
Comments
Post a Comment