Results 1 to 1 of 1

Thread: Zip directory ready for download

  1. #1
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Unhappy Zip directory ready for download

    Hi I have found this script for zipping up directorys how would I zip all file EXCEPT 2, index.html and style.css

    Here's the code

    PHP Code:
    function Zip($source$destination)
    {
       if (!
    extension_loaded('zip') || !file_exists($source)) {
        return 
    false;
     }

     
    $zip = new ZipArchive();
     if (!
    $zip->open($destinationZIPARCHIVE::CREATE)) {
     return 
    false;
     }

     
    $source str_replace('\\''/'realpath($source));

     if (
    is_dir($source) === true)
     {
     
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

     foreach (
    $files as $file)
     {
     
    $file str_replace('\\''/'realpath($file));

    if (
    is_dir($file) === true)
     {
     
    $zip->addEmptyDir(str_replace($source '/'''$file '/'));
     }
    else if (
    is_file($file) === true)
    {
    $zip->addFromString(str_replace($source '/'''$file), file_get_contents($file));
     }
     }
     }
    else if (
    is_file($source) === true)
    {
     
    $zip->addFromString(basename($source), file_get_contents($source));
     }
     return 
    $zip->close();

    Thanks


    Code from here http://stackoverflow...irectory-in-php
    Last edited by TwitterRooms; 04-21-2012 at 12:06 PM. Reason: Missing } sorry

Bookmarks

Posting Permissions

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