Customer Portal

Get Involved. Join the Conversation.

Topic

    Janusz Jasinski
    How to unzip a file in RNCPHP
    Topic posted September 26, 2019 by Janusz JasinskiSilver Crown: 22,500+ Points, last edited November 9, 2019 
    29 Views, 4 Comments
    Title:
    How to unzip a file in RNCPHP
    Content:

    Hi,

    Using ZipArchive doesn't seem to work - any ideas?

    Thanks,

    JJ

    Comment

     

    • Kenton Banyai

      If you right click on the file, you should be able to click an extract option. Then you choose the destination folder you want it extracted.

      • Janusz Jasinski

        Is this a joke?

        • Sebastiaan Draaisma

          I suspect Kenton hasn't worked much with CPM and assumed RNCPHP was a local directory.

          I found very little info on zip/unzip on the forum and nothing in the technical doc.
          I did some searching and may have found an alternative to zipArchive that I have not tested myself

          <?php          
          function unzip($location,$new_location){
              if(exec("unzip $location",$arr)){
                  mkdir($new_location);
                  $source_dir = dirname($location);
                  for($i = 1;$i< count($arr);$i++){
                      $file = trim(preg_replace("~inflating: ~","",$arr[$i]));
                              copy($source_dir."/".$file,$new_location."/".$file);
                              unlink($source_dir."/".$file);
                      }
                  return true;
              }
              return false;      
          }
           
          // usage of this code
          if(unzip('ziped_files/test.zip','unziped_files/newfile')){
              echo 'Successfully unzipped!';
          }else{
              echo 'Error while processing your file!';
          }
          ?>