We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11055 ☆ A M B ☆
    • 3,112 Posts
    I’m almost finishing the UTF-8 support for Easy 2 Gallery module/snippet.
    But I got a trouble on un-ZIP-ing the UTF-8 file.

    I’ve make a change around the un-ZIP-ed code (using Pclzip.php)
    <?php // for highlighting
    $extract = $zip->extract(PCLZIP_OPT_PATH, '../'.$gdir,
                             PCLZIP_CB_PRE_EXTRACT, 'zipPreExtractCallBack');
    if ( $extract == 0 ) {
        $_SESSION['easy2err'][] = "Error : ".$zip->errorInfo(TRUE);
    } else {
        $_SESSION['easy2suc'][] = $j.' '.$lng['files_uploaded'].'.';
    }
    


    And the Call back function:
    <?php 
    /*
     * PclZip PCLZIP_CB_PRE_EXTRACT to convert filenames while extracting the content.
    */
    function zipPreExtractCallBack($p_event, &$p_header) {
        $info = pathinfo($p_header['filename']);
        $p_header['filename'] = iconv("ISO-8859-1", "UTF-8", $p_header['filename']);
        return 1;
    }
    


    But the result goes:

    Error : PCLZIP_ERR_INVALID_OPTION_VALUE (-16) : Function ’zipPreExtractCallBack()’ is not an existing function for option ’PCLZIP_CB_PRE_EXTRACT’

    If anyone has an idea to resolve this, please let me know.
      Rico
      Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
      MODx is great, but knowing how to use it well makes it perfect!

      www.virtudraft.com

      Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

      Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

      Maintainter/contributor of Babel

      Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      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.
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 11055 ☆ A M B ☆
        • 3,112 Posts
        OK,
        I ended up this business by doing this

        <?php
        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') {
                    $get_host_iconv_encode = iconv_get_encoding("internal_encoding");
                    $get_file_mb_encode = mb_detect_encoding( $info['basename'] );
                    $p_header['filename'] = iconv( $get_host_iconv_encode , $get_file_mb_encode.'//TRANSLIT//IGNORE' , $p_header['filename'] );
                    return 1;
                }
                // other file extension will not be unzipped
                else return 0;
            }
        }
        


        I hope this helps others.
          Rico
          Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
          MODx is great, but knowing how to use it well makes it perfect!

          www.virtudraft.com

          Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

          Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

          Maintainter/contributor of Babel

          Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.