Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    San Diego, CA
    Posts
    64
    Thanks
    2
    Thanked 1 Time in 1 Post

    Post Extracting a specific folder from a Zip on the server

    PHP Code:
    <?php
    function extractDir($zipfile$path) {
      if (
    file_exists($zipfile)) {
        
    $files = array();
        
    $zip = new ZipArchive;
        if (
    $zip->open($zipfile) === TRUE) {
          for(
    $i 0$i $zip->numFiles$i++) {
            
    $entry $zip->getNameIndex($i);
            
    //Use strpos() to check if the entry name contains the directory we want to extract
            
    if (strpos($entry"/MyFolder/")) {
              
    //Add the entry to our array if it is in our desired directory
              
    $files[] = $entry;
            }
          }
          
    //Feed $files array to extractTo() to get only the files we want
          
    if ($zip->extractTo($path$files) === TRUE) {
            return 
    TRUE;
          } else {
            return 
    FALSE;
          }
          
    $zip->close();
        } else {
          return 
    FALSE;
        }
      } else {
        return 
    FALSE;
      }
    }

    //Run the function
    if (extractDir($zipfile$path)) {
      
    $extracted "YES! :-D";
    } else {
      
    $extracted "NO! :*(";
    }

    echo 
    $extracted;
    ?>
    Last edited by Gremlyn1; 12-03-2009 at 05:48 PM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •