Yikes! I almost give up, I need a hand here.
The PCLZIP_CB_PRE_EXTRACT function has been working successfully.
Now new problem with encoding.
I attempt to convert the UTF-8 filename while unZIPing with pclzip library.
I’ve tried many methods but I couldn’t find any of them working.
<?php
// not working
header('Content-Type: text/html; charset=UTF-8');
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("input_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "UTF-8");
<?php
class e2g_mod {
private function _explore() {
/*
* PclZip PCLZIP_CB_PRE_EXTRACT to convert filenames while extracting the content.
*/
if (!function_exists('zipPreExtractCallBack')) {
function zipPreExtractCallBack($p_event, &$p_header) {
$info = pathinfo($p_header['filename']);
// limit the unzipped images
if ($info['extension'] == 'jpeg' || $info['extension'] == 'jpg' || $info['extension'] == 'gif' || $info['extension'] == 'png') {
if ( iconv_get_encoding("input_encoding") != "UTF-8" ) {
iconv_set_encoding("input_encoding", "UTF-8");
}
// below is another option
//$p_header['filename'] = iconv("Latin1", "ISO-8859-1", $p_header['filename'] );
//die('125 '.var_dump(iconv_get_encoding('all')));
return 1;
}
// other file extension will not be unzipped
else return 0;
}
}
$extract = $zip->extract(PCLZIP_OPT_PATH, '../'.$gdir
, PCLZIP_CB_PRE_EXTRACT, 'zipPreExtractCallBack'
);
// more codes....
}
}
So, the current issue is the UTF-8.
What do you think?
If you have any idea, please make a guess.