SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Zipping and Deleting folders

    G'day, I am looking for advice on how to efficiently Zip up a directory on a server, download it, and remove it.
    I have a system where users upload photos to a site and all their images get stored in a directory. I want the Admin users to be able to download this directory and then be able to delete the directory off the server. Please advise...

  2. #2
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The simple way would be to exec() a tar command to tar and gzip the directory, then move that tarball anywhere you need it. If you need an actual zip file (pkzip compression), you can do the same thing, assuming the server has zip installed.
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  3. #3
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there does also exist a zip thing in php, take a look at http://is.php.net/manual/en/ref.zip.php.
    It is not supported by all servers though and I personally have never used it...
    - website

  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by website
    there does also exist a zip thing in php, take a look at http://is.php.net/manual/en/ref.zip.php.
    It is not supported by all servers though and I personally have never used it...
    CXII. Zip File Functions (Read Only Access)
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  5. #5
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh, curse it
    - website

  6. #6
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what about

    CXIII. Zlib Compression Functions

    http://is.php.net/manual/en/ref.zlib.php
    the neigbours (free) WIFI makes it just a little more fun

  7. #7
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by peanuts
    what about

    CXIII. Zlib Compression Functions

    http://is.php.net/manual/en/ref.zlib.php
    That's just an interface to gzip. Since you're going to have to tar anyway, why not do it in one fell swoop?
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  8. #8
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys, I am having a problem using the exec() command at the moment. I use it to create a .tar file, but then try it again to move ("mv") the .tar file, and no luck. My syntax should be correct because I use the exact same in my Terminal and it works. And permissions should be ok I figure. Any ideas?

  9. #9
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got a script (that uses a zip creation class that's in phpmyadmin) to zip files in the ZIP file format. Let me know if you're interested.

  10. #10
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i am redemption... please enlighten me. restore my faith in PHP (hehe, just kiddin it's the sheeeet!)

  11. #11
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK first grab the zip.lib.php file that comes with phpmyadmin - it's the script that does the actual zipping.

    Here's a test script (zips 'test2.php' and 'apache_pb.gif' into a file called archivetest.zip) I used to see how it works - you need to do the work of placing the correct files in the zip archive yourself. A loop would do the trick. Sorry for not being clearer, but I'm in a hurry at the moment.
    PHP Code:
    <?php

    include("./zip.lib.php");

    $file_name 'test2.php';
    $file_contents file_get_contents($file_name);

    $zipfile = new zipfile();

    $zipfile->addfile($file_contents$file_name);

    $file_name 'apache_pb.gif';
    $file_contents file_get_contents($file_name);

    $zipfile->addfile($file_contents$file_name);

    $file $zipfile->file();

    $size sizeof($file);
    header("Cache-control: private");
    if( 
    stristr($_SERVER['HTTP_USER_AGENT'], 'Gecko') )
        
    header("Content-type: application/x-zip-compressed\n");
    else
        
    header("Content-Type: application/octet-stream\n");
    header("Content-transfer-encoding: binary\n");
    //header("Content-Length: $size" );

    $archive_name 'archivetest';

    if( 
    stristr($_SERVER['HTTP_USER_AGENT'], 'Gecko') ) {
        
    header("Content-Disposition: attachment; filename=".$archive_name.".zip"); 

    else {
        
    header("Content-Disposition: filename=".$archive_name.".zip","zip");
    }

    if( !
    readfile($file) )
        echo 
    'There has been an error archiving the file.';

    ?>

  12. #12
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you redemption, i be trying this out...


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
  •