SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Zip a folder with PHP

    I'm looking for a way to zip folders with php and provide a download link to them. any ideas?
    I tried PclZip, but I get errors, and I don't really know how to solve them, cause I've never worked with zips before.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What errors do you get?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Addict talence's Avatar
    Join Date
    Mar 2006
    Location
    Tux
    Posts
    269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you use this:

    Code:
    <?php
    exec("tar -c sourcefolder destinationfolder.tar.gz");
    ?>
    this will work only if you server support exec() function or not having safe_mode enabled.

    Regards
    Mellowhost - Affordable Cpanel and WHM Reseller Hosting
    R1Soft, RVSitebuilder, RVSkin, Softaculous, Fantastico
    Learn Hosting

  4. #4
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's my error "Error : PCLZIP_ERR_READ_OPEN_FAIL (-2) : Unable to open archive 'Transparentia.zip' in wb mode"

    Using this code:
    PHP Code:
    <?php
    //download library from http://www.phpconcept.net/pclzip/index.en.php#download
    include('pclzip.lib.php');
    //zip file name
    $new_zip= new PclZip('backup.zip');
    //backup theimages folder
    $file_list $new_zip->create('images/');
    if (
    $file_list == 0
    {
    die(
    "Error : ".$new_zip->errorInfo(true));
    }
    echo 
    "Successfully created zip file";
    ?>
    which I found at a site.
    I double checked, it's loading the pclzip.lib.php file, so that's not the problem.

    talence: It needs to be zip, so that it's user friendly.

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try zip if it's available:
    PHP Code:
    exec("zip -r output/files.zip path/to/dir"); 
    Make sure you set the right permissions for the destination directory (in this case 'output').
    Saul

  6. #6
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's not working, so I guess my server configuration doesn't allow it. any other suggestions?

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Edit:

    sounds like php doesnt have write permissions.
    is the directory youre trying to create the zip in, writiable by php?

  8. #8
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's the file i'm trying to create

  9. #9
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i changed the permissions, and now it says "Successfully created zip file", but i don't know where it put it... anyone use this script before?

  10. #10
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you cant use ftp and look?

  11. #11
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i found it, in the directory the script was in, but i cant figure out how to change that, plus it zips up the whole directory structure, from the server root, which isn't desirable.
    Anyone know some simple tutorial/script/library with clear instructions in readable english?


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
  •